Home > Net >  how to get all field on modelform on django
how to get all field on modelform on django

Time:06-11

I have a model called Product

class Product(models.Model):
    id
    name
    nation
    Number
    price

i want to filter using all of the above attributes, which will be passed in query_params

at this moment i am using DjangoFilterBackends with filter_fields but to support all attributes i have to mention all the attributes in filter_fields like below in views

filter_fields = ['id', 'name', 'nation', 'Number', 'price']

its working fine, but in actual model the fields are alot, which is causing code quality degradation.

is there any way to include all fields in filter_fields ?? i tried filter_fiels = ['__all__'], but its not working.

CodePudding user response:

You have to write your code like this:

filter_fields = '__all__'
  • Related