milandjukic88
milandjukic88

Reputation: 1115

Getting Model class fields not working well

i'm trying to get all fields from db.Model class. For example: I have two classes A and B. Class A have 3 fields and class B have 2 but one of two fields in class B is foreign key from class A. When i do this: A._meta.get_all_field_names() i get and field from class B where is that field foreign key for B from A. Why?

Upvotes: 1

Views: 38

Answers (1)

alecxe
alecxe

Reputation: 473873

It works as intended, here's get_all_field_names()'s docstring:

Returns a list of all field names that are possible for this model (including reverse relation names).

If you don't want to see fields from related models, just read fields from _meta.fields:

[field.name for field in A._meta.fields]

Upvotes: 1

Related Questions