A
A
Antigo_ptz2017-01-11 09:03:23
Django
Antigo_ptz, 2017-01-11 09:03:23

How to get a list of related entities from a model in Django?

Hello!
In the code, I got the Worker model (worker). An employee has nested entities such as place of work, address, and so on. (one-to-many relationship) Can I get a list of these related entities from the Worker model. It is with one-to-many connections. Tried through model._meta.related_objects, but there are also entities with other relationships in the list.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2017-01-11
@deliro

The fields you can get from _meta.get_fields() have boolean fields: is_relation, one_to_one, many_to_one, one_to_many, many_to_many.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question