1👍
✅
The filter
method returns a QuerySet
and not one model instance. A QuerySet
is a Django object that represents a query to the database, that can be filtered, sliced and iterated to get results. You could get the first result of the QuerySet
with i1[0]
but it is not the best way for you.
In you case, since you are sure to get one and only one result to your query, you need to use the get
method:
i1 = Information.objects.get(pk=1)
# then, this is possible:
i1.informationchild_set.all()
See also: Difference between Django's filter() and get() methods
Source:stackexchange.com