ORM: get, filter and DoesNotExist

155 views
Skip to first unread message

zweb

unread,
Apr 4, 2010, 11:33:45 PM4/4/10
to Django users
after some debugging, just found out that
filter method does not throw DoesNotExist while get does.

Russell Keith-Magee

unread,
Apr 5, 2010, 1:56:45 AM4/5/10
to django...@googlegroups.com
On Mon, Apr 5, 2010 at 11:33 AM, zweb <trader...@gmail.com> wrote:
> after some debugging, just found out that
> filter method does not throw DoesNotExist while get does.

get() returns a single object. If a single object does not exist, you
get a DoesNotExist exception. This is documented:

http://docs.djangoproject.com/en/dev/ref/models/querysets/#id5

filter() applies a filtering condition to return a QuerySet of objects
that match the filter. If no objects match the filter, the queryset
can be empty. The result exists - it just doesn't contain anything
(e.g., the set of "all people that are 4m tall" exists, but has no
members). This is also documented:

http://docs.djangoproject.com/en/dev/ref/models/querysets/#filter-kwargs

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages