Esempio n. 1
0
    def __init__(self, field, request, params, model, model_admin, field_path):
        other_model = get_model_from_relation(field)
        if hasattr(field, 'rel'):
            rel_name = field.rel.get_related_field().name
        else:
            rel_name = other_model._meta.pk.name

        self.lookup_formats = {
            'in': '%%s__%s__in' % rel_name,
            'exact': '%%s__%s__exact' % rel_name
        }
        super(RelatedFieldSearchFilter,
              self).__init__(field, request, params, model, model_admin,
                             field_path)

        if hasattr(field, 'verbose_name'):
            self.lookup_title = field.verbose_name
        else:
            self.lookup_title = other_model._meta.verbose_name
        self.title = self.lookup_title
        self.search_url = model_admin.get_admin_url(
            '%s_%s_changelist' %
            (other_model._meta.app_label, other_model._meta.model_name))
        self.label = self.label_for_value(
            other_model, rel_name,
            self.lookup_exact_val) if self.lookup_exact_val else ""
        self.choices = '?'
        if field.rel.limit_choices_to:
            for i in list(field.rel.limit_choices_to):
                self.choices += "&_p_%s=%s" % (i,
                                               field.rel.limit_choices_to[i])
            self.choices = format_html(self.choices)
Esempio n. 2
0
    def __init__(self, field, request, params, model, model_admin, field_path):
        other_model = get_model_from_relation(field)
        if hasattr(field, "rel"):
            rel_name = field.rel.get_related_field().name
        else:
            rel_name = other_model._meta.pk.name

        self.lookup_formats = {"in": "%%s__%s__in" % rel_name, "exact": "%%s__%s__exact" % rel_name}
        super(RelatedFieldSearchFilter, self).__init__(field, request, params, model, model_admin, field_path)

        related_modeladmin = self.admin_view.admin_site._registry.get(other_model)
        self.relfield_style = related_modeladmin.relfield_style

        if hasattr(field, "verbose_name"):
            self.lookup_title = field.verbose_name
        else:
            self.lookup_title = other_model._meta.verbose_name
        self.title = self.lookup_title
        self.search_url = model_admin.get_admin_url(
            "%s_%s_changelist" % (other_model._meta.app_label, other_model._meta.model_name)
        )
        self.label = self.label_for_value(other_model, rel_name, self.lookup_exact_val) if self.lookup_exact_val else ""
        self.choices = "?"
        if field.rel.limit_choices_to:
            for i in list(field.rel.limit_choices_to):
                self.choices += "&_p_%s=%s" % (i, field.rel.limit_choices_to[i])
            self.choices = format_html(self.choices)
Esempio n. 3
0
 def formfield_for_dbfield(self, formfield, db_field, **kwargs):
     if formfield and self.model in self.admin_site._registry and isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
         rel_model = get_model_from_relation(db_field)
         if rel_model in self.admin_site._registry and self.has_model_perm(rel_model, 'add'):
             add_url = self.get_model_url(rel_model, 'add')
             formfield.widget = RelatedFieldWidgetWrapper(
                 formfield.widget, db_field.rel, add_url, self.get_model_url(self.model, 'add'))
     return formfield
Esempio n. 4
0
 def test(cls, field, request, params, model, admin_view, field_path):
     if not (hasattr(field, 'rel') and bool(field.rel)
             or isinstance(field, ForeignObjectRel)):
         return False
     related_modeladmin = admin_view.admin_site._registry.get(
         get_model_from_relation(field))
     return related_modeladmin and getattr(
         related_modeladmin, 'relfield_style', None) == 'fk-ajax'
Esempio n. 5
0
 def formfield_for_dbfield(self, formfield, db_field, **kwargs):
     if formfield and self.model in self.admin_site._registry and isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
         rel_model = get_model_from_relation(db_field)
         if rel_model in self.admin_site._registry and self.has_model_perm(rel_model, 'add'):
             add_url = self.get_model_url(rel_model, 'add')
             formfield.widget = RelatedFieldWidgetWrapper(
                 formfield.widget, db_field.rel, add_url, self.get_model_url(self.model, 'add'))
     return formfield
Esempio n. 6
0
 def formfield_for_dbfield(self, formfield, db_field, **kwargs):
     if formfield and self.model in self.admin_site._registry and isinstance(db_field, (models.ForeignKey, models.ManyToManyField)) and not getattr(self.admin_view, 'wizard_form_list', None):
         # disable quick add button in wizard form which will caused problems by Eddie -- TBD
         rel_model = get_model_from_relation(db_field)
         if rel_model in self.admin_site._registry and self.has_model_perm(rel_model, 'add'):
             add_url = self.get_model_url(rel_model, 'add')
             formfield.widget = RelatedFieldWidgetWrapper(
                 formfield.widget, db_field.rel, add_url, self.get_model_url(self.model, 'add'))
     return formfield
Esempio n. 7
0
 def formfield_for_dbfield(self, formfield, db_field, **kwargs):
     if db_field.name in self.quick_addbtn_fields_exclude or \
        isinstance(db_field, self.quick_addbtn_db_fields_exclude):
         return formfield  # disabled to this types
     elif formfield and self.model in self.admin_site._registry and \
             isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
         rel_model = get_model_from_relation(db_field)
         if rel_model in self.admin_site._registry and self.has_model_perm(
                 rel_model, 'add'):
             add_url = self.get_model_url(rel_model, 'add')
             formfield.widget = RelatedFieldWidgetWrapper(
                 formfield.widget, db_field.rel, add_url,
                 self.get_model_url(self.model, 'add'), **self.request.GET)
     return formfield
Esempio n. 8
0
    def __init__(self, field, request, params, model, model_admin, field_path):
        other_model = get_model_from_relation(field)
        if hasattr(field, 'rel'):
            rel_name = field.rel.get_related_field().name
        else:
            rel_name = other_model._meta.pk.name

        self.lookup_formats = {'in': '%%s__%s__in' % rel_name,'exact': '%%s__%s__exact' %
                               rel_name, 'isnull': '%s__isnull'}
        self.lookup_choices = field.get_choices(include_blank=False)
        super(RelatedFieldListFilter, self).__init__(
            field, request, params, model, model_admin, field_path)

        if hasattr(field, 'verbose_name'):
            self.lookup_title = field.verbose_name
        else:
            self.lookup_title = other_model._meta.verbose_name
        self.title = self.lookup_title
Esempio n. 9
0
    def __init__(self, field, request, params, model, model_admin, field_path):
        other_model = get_model_from_relation(field)
        if hasattr(field, "rel"):
            rel_name = field.rel.get_related_field().name
        else:
            rel_name = other_model._meta.pk.name

        self.lookup_formats = {
            "in": "%%s__%s__in" % rel_name,
            "exact": "%%s__%s__exact" % rel_name,
            "isnull": "%s__isnull",
        }
        self.lookup_choices = field.get_choices(include_blank=False)
        super(RelatedFieldListFilter, self).__init__(field, request, params, model, model_admin, field_path)

        if hasattr(field, "verbose_name"):
            self.lookup_title = field.verbose_name
        else:
            self.lookup_title = other_model._meta.verbose_name
        self.title = self.lookup_title
Esempio n. 10
0
    def __init__(self, field, request, params, model, model_admin, field_path):
        other_model = get_model_from_relation(field)
        if hasattr(field, 'rel'):
            rel_name = field.rel.get_related_field().name
        else:
            rel_name = other_model._meta.pk.name

        self.lookup_formats = {
            'in': '%%s__%s__in' % rel_name,
            'exact': '%%s__%s__exact' % rel_name,
            'isnull': '%s__isnull'
        }
        self.lookup_choices = field.get_choices(include_blank=False)
        super(RelatedFieldListFilter,
              self).__init__(field, request, params, model, model_admin,
                             field_path)

        if hasattr(field, 'verbose_name'):
            self.lookup_title = field.verbose_name
        else:
            self.lookup_title = other_model._meta.verbose_name
        self.title = self.lookup_title
Esempio n. 11
0
    def __init__(self, field, request, params, model, model_admin, field_path):
        other_model = get_model_from_relation(field)
        if hasattr(field, 'rel'):
            rel_name = field.rel.get_related_field().name
        else:
            rel_name = other_model._meta.pk.name

        self.lookup_formats = {'in': '%%s__%s__in' % rel_name,'exact': '%%s__%s__exact' % rel_name}
        super(RelatedFieldSearchFilter, self).__init__(
            field, request, params, model, model_admin, field_path)

        if hasattr(field, 'verbose_name'):
            self.lookup_title = field.verbose_name
        else:
            self.lookup_title = other_model._meta.verbose_name
        self.title = self.lookup_title
        self.search_url = model_admin.get_admin_url('%s_%s_changelist' % (
            other_model._meta.app_label, other_model._meta.model_name))
        self.label = self.label_for_value(other_model, rel_name, self.lookup_exact_val) if self.lookup_exact_val else ""
        self.choices = '?'
        if field.rel.limit_choices_to:
            for i in list(field.rel.limit_choices_to):
                self.choices += "&_p_%s=%s" % (i, field.rel.limit_choices_to[i])
            self.choices = format_html(self.choices)
Esempio n. 12
0
 def test(cls, field, request, params, model, admin_view, field_path):
     if not (hasattr(field, 'rel') and bool(field.rel) or isinstance(field, ForeignObjectRel)):
         return False
     related_modeladmin = admin_view.admin_site._registry.get(
         get_model_from_relation(field))
     return related_modeladmin and getattr(related_modeladmin, 'relfield_style', None) == 'fk-ajax'
Esempio n. 13
0
 def test(cls, field, request, params, model, admin_view, field_path):
     if not is_related_field2(field):
         return False
     related_modeladmin = admin_view.admin_site._registry.get(get_model_from_relation(field))
     return related_modeladmin and getattr(related_modeladmin, "relfield_style", None) in ("fk-ajax", "fk-select")