2👍
Use get()
instead of filter()
:
the_team = Team.objects.get(name='Django_FC')
Quote from docs:
filter()
will always give you aQuerySet
, even if only a single object
matches the query – in this case, it will be a QuerySet containing a
single element.If you know there is only one object that matches your query, you can
use theget()
method on a Manager which returns the object directly.
Source:stackexchange.com