Sunday, February 13, 2011

Re: Django ORM queryset problem

It works. Seems that I never understood the power of these Q objects.
Thank you! ez

On Feb 13, 3:12 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Sunday, February 13, 2011 12:48:25 PM UTC, ezorro wrote:
>
> > Hi django users!
>
> > I have two simple models: Person and Address.
>
> > class Person(models.Model):
> > first_name = models.CharField(max_length=64, blank=True, default='')
> > last_name = models.CharField(max_length=64, blank=True, default='')
>
> > class Address(models.Model):
> > person = models.ForeignKey(Person)
> > street = models.CharField(max_length=64, blank=True, default='')
> > postal_code = models.CharField(max_length=32, blank=True, default='')
> > city = models.CharField(max_length=64, null=True, blank=True,
> > default='')
>
> > I would like a queryset of Persons where first_name or city equals
> > 'Paris'
> > Any ideas?
>
> Person.objects.filter(Q(first_name="Paris") | Q(address__city="Paris"))
> --
> DR.

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate