Skip to content

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

Open
@uroybd

Description

@uroybd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions