You should use 'F' expression from django.db.models
So your expression would be like: 
ProductSale.objects.all().filter(date_expires__lg = 
now()).exclude(date_purchased__gt 
= F('date_expires'))



On Tuesday, 18 August 2015 06:26:56 UTC+5:30, Lee Hinde wrote:
>
> Given this model, I want to find all ProductSale objects that have expired 
> and where the Person doesn't have a later (unexpired) purchase of the same 
> product.
>
> class ProductSale(models.Model):
>     product = models.ForeignKey(Product)
>     person = models.ForeignKey(Person)
> ...
>     date_expires = models.DateField(blank=True, db_index=True)
>     
>
> The closest I've gotten is in the shell where I get a values_list of 
> person and product for expired and unexpired and then compare the two 
> lists. That leaves me with a list of tuples, that (due to the size of the 
> list, I think) I can't use in a query.extra. 
>
> Any suggestions would be appreciated.
>
> (and sorry for the lame subject. I couldn't think of a way to be both 
> succinct and informative.)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/daa1c2a5-1c8d-41f4-b4ca-73d0f6c70a1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to