“_Set in Django” Code-Antworten

_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()
Panicky Pintail

_set.filter django

>>> r.article_set.filter(headline__startswith='This')
<QuerySet [<Article: This is a test>]>

# Find all Articles for any Reporter whose first name is "John".
>>> Article.objects.filter(reporter__first_name='John')
<QuerySet [<Article: John's second story>, <Article: This is a test>]>
Bottle Vines

Ähnliche Antworten wie “_Set in Django”

Fragen ähnlich wie “_Set in Django”

Weitere verwandte Antworten zu “_Set in Django” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen