V
V
Vladimir Kuts2017-07-25 12:18:26
Django
Vladimir Kuts, 2017-07-25 12:18:26

Efficient DB fetch?

There are the following models:

class User(models.Model):
    ...

class UserSettings(modes.Model)
    user = models.OneToOneField(User)
    hide_from = models.ManyToManyField(User)
    ...

class Post(models.Model):
    user = models.ForeignKey(User)
    ...

Now there is some object of class User, say user1, who wants to get a selection of all Posts. How can I use Django ORM to exclude instances from the Post selection in ONE query, whose user in UserSettings has this user user1 in the "hide_from" field set?

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