_set in Django for a set of queries

I'm a little confused about how to use _setin a query set in Django. For example, a Blog object b, and the object Entryis bound by an attribute entry_set. What is the point b.entry_set.all()? I would appreciate it if someone could use this example to display possible output.

+4
source share
1 answer

What you see is a reverse lookup of objects .

In your example:

class Blog(models.Model):
    pass

class Entry(..):
    blog = Blog(..)

, e Entry, e.blog Blog - . _set - django .

, b - :

entries = b.entry_set.all()

, , - ForeignKey - 1-to-many. , - .

_set , related_name .

+10

Source: https://habr.com/ru/post/1668999/


All Articles