Tuesday, March 27, 2012

Re: Simple question on queryset.

On Tue, Mar 27, 2012 at 1:57 AM, Stanwin Siow <stanwin.ktsiow@gmail.com> wrote:
> queryset = Memberships.objects.get(id__exact=4)

the .get() method doesn't return a queryset, it returns a record
object, so your 'queryset' variable is the 'membership' object itself.

the error you get:

> Memberships has no attribute all.

means exactly that, you already have a Membership object, no need to
iterate it calling .all()

using the .filter() call you do get a queryset, but since you're using
the primary key, you won't ever get more than one object, so it is
more appropriate to use .get()

--
Javier

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment