K
K
Kirill2021-02-10 00:48:55
Django
Kirill, 2021-02-10 00:48:55

Querying data from a database from two ForeignKey tables?

There are 2 models in models.py

class point(models.Model):
    _user = models.ForeignKey(
        User,
        on_delete=models.CASCADE,
        verbose_name='Модель пользователя'
    )
    title= models.TextField(
        verbose_name='Название',
    )

class gallery_images(models.Model):
    _point = models.ForeignKey(
        point,
        on_delete=models.CASCADE
    )
    image = models.ImageField(
        upload_to='photo'
    )


How to get a list of all items and in addition for each of his photos? To avoid N + 1
Either through Django, or pure SQL through raw

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question