form as filter in admin site

33 views
Skip to first unread message

Luis Zárate

unread,
Feb 20, 2016, 10:57:55 AM2/20/16
to django...@googlegroups.com
I am trying to insert a filter in the admin site that have 2 autocomplete inputs so I was thinking to do  passed a form  with a custom filter, but I only find a list filter documentation.

I solved the problem writing a custom filter, with a little problem with css, because change list view  has few width space for filter so input looks terrible.

i needed to search in the django code because i didn't find in documentation.

I think my solution is generic so I am asking me if django has this functionally implemented, I didn't find but maybe you know something about.

--
"La utopía sirve para caminar" Fernando Birri



Luis Zárate

unread,
Feb 22, 2016, 12:24:41 PM2/22/16
to django...@googlegroups.com
I need something like this, of course magic is in FormFilter :), so I am lookig for something in admin app with this behaivor


class MatriculaForm(forms.Form):
    # I am using django-ajax-selects, lookups are out of scope
    disciplina = AutoCompleteSelectMultipleField('disciplinas',
                                                 required=False,
                                                 help_text=None)
    ciclo = forms.ModelMultipleChoiceField(queryset=Ciclo.objects.all(),
                                           required=False)
    proyecto = AutoCompleteSelectMultipleField('proyectos',
                                               required=False,
                                               help_text=None)



class MatriculaFilter(FormFilter):
    template = "matriculafilter/filter_template.html"
    form = MatriculaForm
    title = "Matricula Filter"
    # Needs for autocomplete fields that insert other input
    remove_params = ['filtro', 'disciplina_text', 'proyecto_text']
    #Map form fields with model fields for example FK relations
    map_parameters = {'ciclo': 'proyeccion__ciclo'}



class MatriculaAdmin(admin.ModelAdmin)
    list_filter = (
                   MatriculaFilter,
                   )
FormFilter.py
Reply all
Reply to author
Forward
0 new messages