Exemple #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)

        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)
Exemple #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)

        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.module_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)
Exemple #3
0
 def test(cls, field, request, params, model, admin_view, field_path):
     if not (hasattr(field, 'rel') and bool(field.rel)
             or isinstance(field, RelatedObject)):
         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'
Exemple #4
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')
Exemple #5
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 = {'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
Exemple #6
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 = {'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
Exemple #7
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 = {'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.module_name))
        self.label = self.label_for_value(other_model, rel_name, self.lookup_exact_val) if self.lookup_exact_val else ""
Exemple #8
0
 def test(cls, field, request, params, model, admin_view, field_path):
     if not (hasattr(field, 'rel') and bool(field.rel) or isinstance(field, models.related.RelatedObject)):
         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'
Exemple #9
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')