Foreign key is set in one-to-many relation.
For example,
Publisher – Book
—-
class Book(models.Model):
publisher = models.ForeignKey(Publisher)
—–
There are two cases:
>>> b = Book.objects.get(id=78)
>>>b.publisher
>>>p=Publisher.objects.get(name=’Aplus’)
>>>p.book_set.all()
Note that book_set
is just a QuerySet.
Thus it can be filtered and sliced.
>>>p.book_set.filter(name__icontains=’django’).order_by(‘name’)[0:2]
