django rest framework use all and extend fields in a serializer 1

django rest framework use all and extend fields in a serializer

model = MyModel
fields = [field.name for field in model._meta.fields]
fields.append('any_other_field')

Here is what the above code is Doing:
1. It’s getting the model class from the model module.
2. It’s getting the list of field names from the model class.
3. It’s adding the name of the field that you want to add to the list.
4. It’s assigning the list to the fields attribute of the ModelResource class.

Similar Posts