Query that feeds grid and subgrid? [closed]

1

How to, for example, generate:

Autor 1
+-- Livro 1
+-- Livro 2

Autor 2
+-- Livro 3
+-- Livro 4

using django-rest-framework? This in one query only?

I searched for it with query and details .. but not exactly like this ..: /

    
asked by anonymous 13.12.2013 / 14:07

2 answers

2

First of all, it is good to take into consideration that your models are well-connected. To do this, ask yourself: Can I get this return using just the Django ORM? (as the friend @Adir replied).

If yes, when you are defining the serialization of your models, you should define the serialization of the relationships between them. In the tutorial on the django-rest-framework website there is a part that teaches how this relationship can be done: link

There is also this chapter in the documentation, which covers a bit more the use of relationships: link

Namely, the relationship between resources is called link (or hyperlink, or hypermedia) according to the REST maturity model, proposed by Leonard Richardson

    
26.12.2013 / 22:33
0

Hello, well I think you should be talking about doing a SQL query. It is usually tricky to bring this organized data from a query but you can do this using Django's ORM if you have the right relationships.

You should probably recover the authors with something like this

autores = Autores.objects.all()

As I said if you did the right relationships you could retrieve all the books associated with the authors, something like

for autor in autores:
    autor.livros.all()
    
13.12.2013 / 14:43