J
J
Jundallah2020-09-15 22:25:20
Django
Jundallah, 2020-09-15 22:25:20

How to filter the list by parent parent?

class Category(models.Model):
        pass

   class News(models.Model):
       category = models.ForeignKey(Category)

   class Message(models.Model):
        news = models.ForeignKey(News)


How can I filter messages by a specific category ID?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-09-15
@gebrak

For example, like this:
Message.objects.filter(news__category__in=[])
https://docs.djangoproject.com/en/3.1/topics/db/qu...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question