Re: How to select a single field from database with django QuerySet API?
Thanks!!! On Feb 26, 10:28 am, Eric Abrahamsen wrote: > On Feb 26, 2009, at 6:23 PM, marco sedda wrote: > > > > > Hi, > > I want to select a "single" field from a table, i've read the > > QuerySet API reference but i can't find anything to solve my query. > > > Just to explain: > > > If i've a table like: > > > User > > first_name = models.CharField(max_length=30) > > last_name = models.CharField(max_length=30) > > > how i can execute a sql query "SELECT first_name FROM User" with > > QuerySet API? > > You want the values() queryset call > (http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields > ). Your query would probably look like > User.objects.values('first_name'), or if you wanted a plain list > (values usually returns a dictionary), you can use values_list() with > the 'flat' parameter. > > Hope that helps, > Eric > > --~--~-~--~~~---~--~~ 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: How to select a single field from database with django QuerySet API?
On Feb 26, 2009, at 6:23 PM, marco sedda wrote: > > Hi, > I want to select a "single" field from a table, i've read the > QuerySet API reference but i can't find anything to solve my query. > > Just to explain: > > If i've a table like: > > User > first_name = models.CharField(max_length=30) > last_name = models.CharField(max_length=30) > > how i can execute a sql query "SELECT first_name FROM User" with > QuerySet API? You want the values() queryset call (http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields ). Your query would probably look like User.objects.values('first_name'), or if you wanted a plain list (values usually returns a dictionary), you can use values_list() with the 'flat' parameter. Hope that helps, Eric > > > --~--~-~--~~~---~--~~ 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: How to select a single field from database with django QuerySet API?
On Thu, Feb 26, 2009 at 7:23 PM, marco sedda wrote: > > Hi, > I want to select a "single" field from a table, i've read the > QuerySet API reference but i can't find anything to solve my query. > > Just to explain: > > If i've a table like: > > User > first_name = models.CharField(max_length=30) > last_name = models.CharField(max_length=30) > > how i can execute a sql query "SELECT first_name FROM User" with > QuerySet API? Depending on the exact format of the output that you want, either use values(): http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields or values_list(): http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-list-fields Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to select a single field from database with django QuerySet API?
Hi, I want to select a "single" field from a table, i've read the QuerySet API reference but i can't find anything to solve my query. Just to explain: If i've a table like: User first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) how i can execute a sql query "SELECT first_name FROM User" with QuerySet API? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---