Django versions 1.8 and later:
You should use get_fields()
:
[f.name for f in MyModel._meta.get_fields()]
The get_all_field_names()
method is deprecated starting from Django
1.8 and will be removed in 1.10.
The documentation page linked above provides a fully backwards-compatible implementation of get_all_field_names()
, but for most purposes the previous example should work just fine.
Django versions before 1.8:
model._meta.get_all_field_names()
That should do the trick.
That requires an actual model instance. If all you have is a subclass of django.db.models.Model
, then you should call myproject.myapp.models.MyModel._meta.get_all_field_names()