Answers for "_set in django"

1

_set in django

# Now, given object e of type Entry, you would do e.blog to access 
# the related object Blog - which is a forward relation. 

class Blog(models.Model):
    pass

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

# The _set is a reverse lookup class variable django puts in for you.    
# So, given object b - you would do:
entries = b.entry_set.all()
Posted by: Guest on September-12-2021

Python Answers by Framework

Browse Popular Code Answers by Language