CrazySynthax
CrazySynthax

Reputation: 15008

Django Model: how to find list of auto-generated fields

Is there any Django built-in function that return a list of all auto-generated fields from a Django model?

Something like: MyModel._meta._get_auto_generated_fields()

Upvotes: 2

Views: 34

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476659

You can filter the fields with list comprehension on the .auto_generated attribute [Django-doc]:

[field for field in MyModel._meta.get_fields() if field.auto_created]

Upvotes: 2

Related Questions