dogewang
dogewang

Reputation: 678

Get m2m field (with through model) list in django

I'm using Django 2.0.7.

I want to get all the fields of a model. I can get all the normal fields in:

model._meta.fields

And I can get m2m fields in:

model._meta.local_many_to_many

However, if the m2m field has an through table, I can't access them? How can I achieve this?

Upvotes: 1

Views: 1233

Answers (2)

Endre Both
Endre Both

Reputation: 5740

The m2m fields have a through model that you can access:

YourModel.m2m_field.through._meta.fields

Upvotes: 1

Rabin Lama Dong
Rabin Lama Dong

Reputation: 2476

Did you try this ?

model._meta.get_all_field_names()

Upvotes: 0

Related Questions