On Sun, May 17, 2009 at 11:58 AM, Lokesh <lokeshmarema...@gmail.com> wrote:
> > Hi, > > class BasicDetails(models.Model): > age = models.PositiveSmallIntegerField(null=False, blank=False) > dom = models.PositiveSmallIntegerField(null=False, blank=False) > dod = models.PositiveSmallIntegerField(null=False, blank=False) > doy = models.PositiveIntegerField(null=False, blank=False) > gender = models.CharField(max_length=1) > > Below I have provided the queries with results which I executed from > mysql prompt. > I am not able to figure out the django queries for these sql queries. > Could some one please guide me on resolving the below mysql queries in > django. > > mysql> select * from polls_basicdetails; > Django---> polls_basicdetails.objects.all() > > +----+-----+-----+-----+------+--------+ > | id | age | dom | dod | doy | gender | > +----+-----+-----+-----+------+--------+ > | 1 | 18 | 1 | 1 | 1991 | M | > | 2 | 19 | 1 | 1 | 1991 | M | > | 3 | 20 | 1 | 1 | 1991 | M | > | 4 | 18 | 1 | 1 | 1991 | M | > +----+-----+-----+-----+------+--------+ > > mysql> select distinct age from polls_basicdetail > Django ----> ????????????? > +-----+ > | age | > +-----+ > | 18 | > | 19 | > | 20 | > +-----+ > > mysql> select age, dom from polls_basicdetails; > Django ----> ????????????? > +-----+-----+ > | age | dom | > +-----+-----+ > | 18 | 1 | > | 19 | 1 | > | 20 | 1 | > | 18 | 1 | > +-----+-----+ > > Thanks for your time. > > Regards, > Lokesh > > > > > For the first one you want: Model.objects.values_list('age', flat=True).distinct() for the second: Model.objects.values('age', 'dom') Hopefully those are self-explanitory, if not: http://docs.djangoproject.com/en/dev/topics/db/queries/ :) Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---