Django filters - Using an AllValuesFilter (with a LinkWidget) on a ManyToManyField -


This is my first stack overflow question, so please let me know that I am doing something wrong.

Using the amazing django-filters application, I want to create an alveolar filter on many grounds. Actually, I want to make a filter that looks like it's in the admin, so I also want to use LinkWidget. # Model class organization (models.Model): Unfortunately, I get an error (invalid field name: 'operator'):

  names = Models.CharField () ... class sign (models.Model): name = models.CharField () operator = models.ManyToManyField ('organization', empty = true) ... # filter class SignFilter (LinkOrderFilterSet): operator = Django_filters.AllValuesFilter (widget = django_filters.widgets.LinkWidget) Category Meta: Model = Sign Fields = ['Operator']  

Many people have found many relationships by creating their filters with it. Coded:

  # Model class Formation (models.Model): name = models.CharField () ... class symbol (models.Model): name = models.CharField () Operator = models.ManyToManyField ('organization', empty = true) ... # Filter class MyFilter (django_filters.ChoiceFilter): @property def field (self): cd = {} in the line self.model.objects.all (): orgs = row.operator.select_related (). Value for org in orgs (): CD [org ['id']] = org ['name'] option = zip (cd.keys (), cd.values ​​()) list.sort (option, key) = Lambda x: (x [1], x [0])) self.extra ['option'] = return return option (AllValuesFilter, manually) .field class SignFilter (LinkOrderFilterSet): operator = MyFilter (widget = django_filters.widgets .LinkWidget)  

I'm new to Python and Django. Can someone think of a more common / elegant way of doing this?

You can use it

  class circle filter (django_filters. FilterSet: l = [] for the Organization.Com.O.Ol (): l.append ((c.id, c.name)) operator = django_filters.ChoiceFilter (option = set (L)) class meta: model = Sign field = ['operator']  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -