You should use 'F' expression from django.db.models
So your expression would be like:
ProductSale.objects.all().filter(date_expires__lt = now().date).exclude(
date_purchased__gt = F('date_expires'))
Which roughly translates to
SELECT * FROM productsale WHERE date_expires < CURRENT_DATE AND NOT
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
t;>>> event pages, each event page can be tagged (using taggit), and I want to
>>>>> produce a list of distinct tags used in the events that belong to that
>>>>> event index on the index itself. I'm using the Django CMS Wagtail, but I
>>>>> guess this i
;> In my models I have an event index page type, which can have child
>>>> event pages, each event page can be tagged (using taggit), and I want to
>>>> produce a list of distinct tags used in the events that belong to that
>>>> event index on the index itse
> pages, each event page can be tagged (using taggit), and I want to produce
>>> a list of distinct tags used in the events that belong to that event index
>>> on the index itself. I'm using the Django CMS Wagtail, but I guess this is
>>> really a Django ORM query
jango CMS Wagtail, but I guess this is
>> really a Django ORM query question. I''ve got some code as part of my model
>> which is working but I don't think it's the most efficient way of doing
>> this. Still trying unlearn doing things with SQL and learn how the same
>&g
want to produce
> a list of distinct tags used in the events that belong to that event index
> on the index itself. I'm using the Django CMS Wagtail, but I guess this is
> really a Django ORM query question. I''ve got some code as part of my model
> which is working but I don't think
this is
really a Django ORM query question. I''ve got some code as part of my model
which is working but I don't think it's the most efficient way of doing
this. Still trying unlearn doing things with SQL and learn how the same
thing should be done in Django.
My code as part of the event index
How do I call django objects from a query for example
licenses = Licenses.objects.all() how I get my licenses,
then im trying to loop through licenses for every object from licenses that
exist in a post save something to vc.
if insert == 'yes':
insert_data = request.POST.copy()
:-)
ModelB.objects.filter(~Q(modelA__fielddate__range(date1,date2)))
On Tue, Feb 26, 2013 at 10:53 AM, ozgur yilmaz wrote:
> Thanks for the replies. I should use exclude, to find A objects, so
> should try this i think:
>
>
Thanks for the replies. I should use exclude, to find A objects, so
should try this i think:
ModelB.objects.exclude(modelA__fielddate__range(date1,date2))
2013/2/26 Ronan Foucher :
> ModelB.objects.filter(modelA__fielddate__range(date1,date2))
>
> Based on the db backend and
ModelB.objects.filter(modelA__fielddate__range(date1,date2))
Based on the db backend and the number of column you can add an index on
fielddate ( check explain output to see if it's useful since it depends on
db backend/ dbengine/structure of the table to make it 'inexpensive' )
~ Ronan
On
yes for me but if you want see the query
you try use django-debug-toolbar and you see how long it takes the query
Cheers
On Tue, Feb 26, 2013 at 11:59 AM, ozgur yilmaz wrote:
> Hi,
>
> Actually my question is not about the date range. i'm planning to use
> __lte and __gte
Hi,
Actually my question is not about the date range. i'm planning to use
__lte and __gte filters. My problem is to solve the query (getting A
objects using B objects) inexpensively. Thanks anyway,
I used:
b_objects = B.objects.filter( activity_date__gte = specific_start_date
,
Hi, maybe use DateField__range(date1,date2)
Cheers
On Tue, Feb 26, 2013 at 5:43 AM, ozgur yilmaz wrote:
> Hi all,
>
> I have to build a query, if possible an inexpensive query:
>
> Model A:
> ...
> ...
>
> Model B:
> ForeignKey( Model A )
> Date
> ...
>
> Model B is an
Hi all,
I have to build a query, if possible an inexpensive query:
Model A:
...
...
Model B:
ForeignKey( Model A )
Date
...
Model B is an activity with a date field. I want to find which Model A
objects didnt join an activity between specific dates.
What are the appropriate ways to find this
Or, using range:
MyModel.objects.filter( Q(a__range=(1,5)) | Q(b__range=(20,70)) )
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects
MyModel.objects.filter( ( Q(a__gt=1) & Q(a__lt=5) ) | ( Q(b__gt=20) &
Q(b__lt=70) ) )
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group,
On 13 April 2010 01:09, zweb wrote:
> how do i do this kind of condition in django orm filter:
>
> ( 1 < a < 5) or ( 20 < b < 70)
>
> select * from table where (a between 1 and 5) or (b between 20 and 70)
>
> --
> You received this message because you are subscribed to
how do i do this kind of condition in django orm filter:
( 1 < a < 5) or ( 20 < b < 70)
select * from table where (a between 1 and 5) or (b between 20 and 70)
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email
Hi Atamert,
Thank you so much!
The following statement works! This is really simple but fantastic!!!
Publication.objects.filter(article__in =
article_qs).annotate(Count('article'))
Sincerely,
Jason
--
You received this message because you are subscribed to the Google Groups
"Django users"
Hi Jason,
On Monday 22 February 2010 09:57:18 Jason wrote:
> If I already had a QuerySet of Article named articles, how to get a
> QuerySet of Publication by these articles,
You can use field lookup operator `in` like this:
>>> Publication.objects.filter(
>>> article_set__id__in =
Dear All,
Model source code:
from django.db import models
class Publication(models.Model):
title = models.CharField(max_length=30)
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)
mystand wrote:
> I need to do a query that selects all Events that a logged in user can edit.
> They can edit an event if they are in the default group, if they are in any
> of the other groups, or they are one of the users added to the event.
first of all, it might be easier if you follow the
missing something. How can I do this query
as elegantly as possible?
Thanks,
A Django Newbie.
--
View this message in context:
http://old.nabble.com/Complex-Query-Question-tp26451658p26451658.html
Sent from the django-users mailing list archive at Nabble.com.
--
You received this message because
On Apr 11, 12:32 pm, Malcolm Tredinnick
wrote:
> That's definitely a small bug, then. I've opened ticket #10790 so that
> it gets fixed eventually. Since it's not a functionality bug (the answer
> is still correct), it will be fixed after 1.1 now, but we will fix it.
On Sat, 2009-04-11 at 01:02 -0700, nikita kozlovsky wrote:
> On Apr 11, 3:11 am, Malcolm Tredinnick
> wrote:
>
>
> > Django's SQL is going exactly what you suspect and not using any outer
> > join here. Using a simplified version of the original two models:
> >
> >
On Apr 11, 3:11 am, Malcolm Tredinnick
wrote:
> Django's SQL is going exactly what you suspect and not using any outer
> join here. Using a simplified version of the original two models:
>
> class Student(models.Model):
> ...
>
> class
On Fri, 2009-04-10 at 05:45 -0700, nikita kozlovsky wrote:
> On Mar 9, 3:21 am, Malcolm Tredinnick
> wrote:
>
> Hello, Malcolm.
>
> > > Again, the correct syntax would be:
> > > Message.objects.filter(student__isnull=True)
>
> Why ORM uses LEFT OUTER JOIN on this
On Mar 9, 3:21 am, Malcolm Tredinnick
wrote:
Hello, Malcolm.
> > Again, the correct syntax would be:
> > Message.objects.filter(student__isnull=True)
Why ORM uses LEFT OUTER JOIN on this query ? Why not "... WHERE
student_id IS NULL" ?
Take it as given that I agree with the bulk of Daniel's reply. It's
correct.
I have one quibble, however...
On Sun, 2009-03-08 at 10:54 -0700, Daniel Roseman wrote:
[...]
> What do you mean by 'student=1'? Do you mean 'the student whose pk is
> 1'? If so, the correct filter syntax for this on
On 8 Mrz., 18:54, Daniel Roseman
wrote:
> On Mar 8, 3:50 pm, Christoph Wegscheider
>
>
>
> wrote:
> > Hi,
> > I have the following model:
> > class Message(models.Model):
> > student = models.ForeignKey(Student, blank=True,
On Mar 8, 3:50 pm, Christoph Wegscheider
wrote:
> Hi,
> I have the following model:
> class Message(models.Model):
> student = models.ForeignKey(Student, blank=True, null=True)
> message = models.CharField(max_length=200)
>
> I want to filter for:
>
Hi,
I have the following model:
class Message(models.Model):
student = models.ForeignKey(Student, blank=True, null=True)
message = models.CharField(max_length=200)
I want to filter for:
message_list = Message.objects.filter(student=1)
OR
message_list =
On Fri, Feb 27, 2009 at 2:40 PM, Bobby Roberts wrote:
>
> hi all. I have a situation where I have two tables, auctions and
> bids. I need to do a subquery as such:
>
> select distinct id from auctions_auction where Active=1 and id IN
> (select distinct AuctionId_id from
hi all. I have a situation where I have two tables, auctions and
bids. I need to do a subquery as such:
select distinct id from auctions_auction where Active=1 and id IN
(select distinct AuctionId_id from auctions_bid where BidderId=6)
how would I do this in django?
> I'm experimenting (so far without success) with a bunch of ways to try
> to turn a chain into a queryset. If anybody has any tips, I will be
> grateful.
Ok, got it, I think - using the idiom from this snippet:
http://www.djangosnippets.org/snippets/26/
(My problem was using the chain to
On Apr 23, 9:00 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> Complex Q-object combinations on trunk do have a few problems (bugs). It
> turns out to be quite hard to get all the combinations working
> correctly. This is one of the areas that development of the
> queryset-refactor branch
On Wed, 2008-04-23 at 06:03 -0700, bobhaugen wrote:
> Replying to myself with more clues:
>
> I see the problem:
>
> For this filter statement:
> items = InventoryItem.objects.filter(
> Q(inventory_date__range=(weekstart, thisdate), received__exact=0)
> |
> Q(onhand__gt=0))
>
>
Replying to myself with more clues:
I see the problem:
For this filter statement:
items = InventoryItem.objects.filter(
Q(inventory_date__range=(weekstart, thisdate), received__exact=0)
|
Q(onhand__gt=0))
,,, the SQL generated looks like this:
SELECT
I'm trying to retrieve all Inventory Items whose onhand quantity is
greater than zero, OR (whose date is within a specified range AND
whose received quantity is zero).
InventoryItems have three relevant fields for this query: onhand,
inventory_date, and received.
I currently have only 2
> class Property(models.Model):
>
> thing = models.ForeignKey(Thing)
> property_type = models.ForeignKey(PropertyType)
> value = models.CharField(...)
> ...
>
> I want to find, for a given PropertyType, all the Things that are
> lacking any Property of that type.
>
>
I believe it would be:
Thing.objects.all().exclude(property__property_type__exact =
type).distinct()
-rfd
On Aug 28, 12:24 pm, James Tauber <[EMAIL PROTECTED]> wrote:
> There's another query I want to do that I can't seem to wrap my head
> around at the moment:
>
> Say I have a model where
There's another query I want to do that I can't seem to wrap my head
around at the moment:
Say I have a model where Things have Properties each of a particular
PropertyType. So
class Property(models.Model):
thing = models.ForeignKey(Thing)
property_type =
Took some custom SQL, but this works well:
content = Content.objects \
.filter(approved__isnull = False) \
.extra(where=['id not in (SELECT content_id FROM
relationship WHERE user_id = %d and "hasRead" = TRUE)' % user.id]) \
.order_by('-created')
On 5/15/07, Collin Anderson <[EMAIL PROTECTED]> wrote:
> class Laptop(models.Model):
> def laptops_out_on(date):
> 'get a list of laptops out on a given day'
> result = Laptop.objects.none()
> for x in Rental.objects.filter(checkout__lte=date,
> checkin__gte=date):
>
I am working with a laptop rental program, and I was wondering if
there is a better way to do this lookup. This works fine, but it seems
like it could be better.
from django.db import models
class Laptop(models.Model):
def laptops_out_on(date):
'get a list of laptops out on a given
On 9/18/06, Tom Smith <[EMAIL PROTECTED]> wrote:
> Not really.. having built and manipulated (with exludes, filters, order
> etc.) I'd quite like to peep at the SQL before it gets executed to see if it
> makes sense
I think it probably is possible by screwing around with internal
variables
On 18 Sep 2006, at 16:26, James Bennett wrote:p.exclude() returns a new QuerySet with the filtering, so you need to grab the return value, like this: if len(notsitelist)>=1: print "excluding sites: ", notsitelist p = p.exclude(fk_site__in=notsitelist) That was it... silly me, just missed
On 18 Sep 2006, at 16:27, Michael Radziej wrote: Is there way to do p.get_query(.)p.show_sql() I really don't get what this is supposed to mean, it just looks like seriously broken syntax. Not really.. having built and manipulated (with exludes, filters, order etc.) I'd quite like to peep at the
On 9/18/06, Tom Smith <[EMAIL PROTECTED]> wrote:
> I have...
>
> p = Product.objects
> if len(notsitelist)>=1:
> print "exluding sites: ", notsitelist
> p.exclude(fk_site__in=notsitelist)
p.exclude() returns a new QuerySet with the filtering, so
Tom Smith wrote:
> Thanks... I'm not sure but I don't think this is working
>
> I have...
>
> p = Product.objects
> if len(notsitelist)>=1:
> print "exluding sites: ", notsitelist
> p.exclude(fk_site__in=notsitelist)
>
> if len(cats)>=1:
>
> Query sets are not executed on the database until you iterate, or
> otherwise try to extract data from them.
>
> o = Recipe.objects
> o2 = o.filter(xx)
> o3 = o2.filter(yy)
> o4 = o3.filter(zz)
>
> print o4
>
> will result in just 1 query getting issued to the database - the final
> query with
On 9/16/06, Tom Smith <[EMAIL PROTECTED]> wrote:
>
> Recipe.objects.exclude(category__in=words)
>
> ...which is great, but now having set words to and empty list [] I
> get the error...
This is an issue that has been previously reported:
http://code.djangoproject.com/ticket/2473
> So... would
On 16 Sep 2006, at 12:42, Malcolm Tredinnick wrote:
>
> On Sat, 2006-09-16 at 12:25 +0100, Tom Smith wrote:
>> How would I build an "AND" query...
>>
>> for example...
>>
>> words = ['chicken', 'beef', 'lamb']
>> Recipe.objects.exclude(title__contains=words)
>>
>> I don't want to do 3
On Sat, 2006-09-16 at 12:25 +0100, Tom Smith wrote:
> How would I build an "AND" query...
>
> for example...
>
> words = ['chicken', 'beef', 'lamb']
> Recipe.objects.exclude(title__contains=words)
>
> I don't want to do 3 queries...
Please start a new thread for new topics, rather than
How would I build an "AND" query...
for example...
words = ['chicken', 'beef', 'lamb']
Recipe.objects.exclude(title__contains=words)
I don't want to do 3 queries...
thanks
tom
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
57 matches
Mail list logo