“_set di Django” Kode Jawaban

_set di 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

Jawaban yang mirip dengan “_set di Django”

Pertanyaan yang mirip dengan “_set di Django”

Lebih banyak jawaban terkait untuk “_set di Django” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya