P
P
proger4042020-12-29 19:55:28
Django
proger404, 2020-12-29 19:55:28

Django ORM query?

There are two tables:

class ModelA(models.Model):
....

class ModelB(models.Model):
    modela: models.ForeignKey(ModelA, related_name="modelb")
....

How can I make a request to get a response like:
{'id': '', 'title': '', 'modelb: [{'id': ''}, {'id': ''}]}

that is, so that the modelb field is combined into an array.
Now I have duplicate entries:
id=1 ... modelb__id ==1
id=1 ... modelb__id ==2
...

help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-12-29
@proger404

https://docs.djangoproject.com/en/3.1/ref/contrib/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question