Re: Simple question on queryset.
On Tue, Mar 27, 2012 at 1:57 AM, Stanwin Siow 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Simple question on queryset.
ok i managed to get it to work by using filter. Cheers Best Regards, Stanwin Siow On Mar 27, 2012, at 3:32 PM, Denis Darii wrote: > I think the error "Memberships has no attribute all" is not related to your > QuerySet. Try to look deeply into your code. > > BTW, your QuerySet must be: > > queryset = Memberships.objects.get(id=4) > > or better, if your id is also the primary key: > > queryset = Memberships.objects.get(pk=4) > > On 27 March 2012 08:57, Stanwin Siow wrote: > > Hello, > > How do i transform this SQL query into a queryset? > > select membership_type from memberships where id ='4' > > i tried the following: > > queryset = Memberships.objects.get(id__exact=4) > > however django is throwing me an error with the following: > > Memberships has no attribute all. > > > I know this is a trivial question but i've been through the tutorials > https://docs.djangoproject.com/en/dev/topics/db/queries/ > > and i don't unds where this error is coming from. > > Do appreciate any help rendered. > > Thank you. > > > Best Regards, > > Stanwin Siow > > > > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > > -- > I'm using Linux because i'm freedom dependent. > > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Simple question on queryset.
I tried changing it to what you said. It's still showing the error. "Memberships object has no attribute all" This only happens when i use get. When i use order_by. the page shows but with unnecessary options. Best Regards, Stanwin Siow On Mar 27, 2012, at 3:32 PM, Denis Darii wrote: > I think the error "Memberships has no attribute all" is not related to your > QuerySet. Try to look deeply into your code. > > BTW, your QuerySet must be: > > queryset = Memberships.objects.get(id=4) > > or better, if your id is also the primary key: > > queryset = Memberships.objects.get(pk=4) > > On 27 March 2012 08:57, Stanwin Siow wrote: > > Hello, > > How do i transform this SQL query into a queryset? > > select membership_type from memberships where id ='4' > > i tried the following: > > queryset = Memberships.objects.get(id__exact=4) > > however django is throwing me an error with the following: > > Memberships has no attribute all. > > > I know this is a trivial question but i've been through the tutorials > https://docs.djangoproject.com/en/dev/topics/db/queries/ > > and i don't unds where this error is coming from. > > Do appreciate any help rendered. > > Thank you. > > > Best Regards, > > Stanwin Siow > > > > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > > -- > I'm using Linux because i'm freedom dependent. > > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Simple question on queryset.
I think the error "Memberships has no attribute all" is not related to your QuerySet. Try to look deeply into your code. BTW, your QuerySet must be: queryset = Memberships.objects.get(id=4) or better, if your id is also the primary key: queryset = Memberships.objects.get(pk=4) On 27 March 2012 08:57, Stanwin Siow wrote: > > Hello, > > How do i transform this SQL query into a queryset? > > select membership_type from memberships where id ='4' > > i tried the following: > > queryset = Memberships.objects.get(id__exact=4) > > however django is throwing me an error with the following: > > Memberships has no attribute all. > > > I know this is a trivial question but i've been through the tutorials > https://docs.djangoproject.com/en/dev/topics/db/queries/ > > and i don't unds where this error is coming from. > > Do appreciate any help rendered. > > Thank you. > > > Best Regards, > > Stanwin Siow > > > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- I'm using Linux because i'm freedom dependent. -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Simple question on queryset.
Hello, How do i transform this SQL query into a queryset? select membership_type from memberships where id ='4' i tried the following: queryset = Memberships.objects.get(id__exact=4) however django is throwing me an error with the following: Memberships has no attribute all. I know this is a trivial question but i've been through the tutorials https://docs.djangoproject.com/en/dev/topics/db/queries/ and i don't unds where this error is coming from. Do appreciate any help rendered. Thank you. Best Regards, Stanwin Siow -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.