Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Allow models to be set as string in AdminChooser #51

Open
uroybd opened this issue May 26, 2022 · 1 comment
Open

FR: Allow models to be set as string in AdminChooser #51

uroybd opened this issue May 26, 2022 · 1 comment

Comments

@uroybd
Copy link

uroybd commented May 26, 2022

Currently, I'm facing circular dependency in AdminChooser and solved this by importing the Model in the __init__ like this:

from django.contrib.admin.utils import quote
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from generic_chooser.widgets import AdminChooser


class DepartmentChooser(AdminChooser):
    def __init__(self, **kwargs):
        from career.models import Department
        self.model = Department
        super().__init__(**kwargs)
        
    choose_one_text = _('Choose a department')
    choose_another_text = _('Choose another department')
    link_to_chosen_text = _('Edit this department')
    choose_modal_url_name = 'department_chooser:choose'

    def get_edit_item_url(self, item):
        from career.wagtail_hooks import DepartmentAdmin
        admin = DepartmentAdmin()
        return admin.url_helper.get_action_url('edit', item.pk)

While it works, it's not really ideal.

Allowing model to be set as String (like SnippetChooserPanel) and resolving it dynamically will provide great ergonomics I believe.

@coredumperror
Copy link

Seconding this request!

I just had to run down a circular import that I couldn't quite determine the cause of, until I realized that my widgets.py was importing my choosable class, and my choosable class was defined in the same file as the model that uses my widget in its form panels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants