Re: Query question

2015-08-17 Thread Dheerendra Rathor
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

Re: Query question

2015-08-17 Thread Dheerendra Rathor
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

Re: ORM Query question

2015-07-13 Thread Joss Ingram
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

Re: ORM Query question

2015-07-13 Thread Avraham Serour
;> 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

Re: ORM Query question

2015-07-13 Thread Joss Ingram
> 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

Re: ORM Query question

2015-07-13 Thread Avraham Serour
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

Re: ORM Query question

2015-07-13 Thread Joss Ingram
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

ORM Query question

2015-07-10 Thread Joss Ingram
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

Referencing Django List Objects From Query Question

2014-06-24 Thread G Z
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()

Re: A query question

2013-02-26 Thread Ronan Foucher
:-) 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: > >

Re: A query question

2013-02-26 Thread ozgur yilmaz
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

Re: A query question

2013-02-26 Thread Ronan Foucher
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

Re: A query question

2013-02-26 Thread carlos
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

Re: A query question

2013-02-26 Thread ozgur yilmaz
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 ,

Re: A query question

2013-02-26 Thread carlos
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

A query question

2013-02-26 Thread ozgur yilmaz
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

Re: ORM Query question

2010-04-12 Thread Tim Shaffer
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

Re: ORM Query question

2010-04-12 Thread Tim Shaffer
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,

Re: ORM Query question

2010-04-12 Thread rebus_
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

ORM Query question

2010-04-12 Thread zweb
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

Re: A Query question about Many-to-many relationships

2010-02-22 Thread Jason
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"

Re: A Query question about Many-to-many relationships

2010-02-22 Thread Atamert Ölçgen
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 =

A Query question about Many-to-many relationships

2010-02-21 Thread Jason
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)

Re: Complex Query Question

2009-11-20 Thread Javier Guerra
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

Complex Query Question

2009-11-20 Thread mystand
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

Re: Foreign Key query question

2009-04-11 Thread nikita kozlovsky
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.

Re: Foreign Key query question

2009-04-11 Thread Malcolm Tredinnick
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: > > > >

Re: Foreign Key query question

2009-04-11 Thread nikita kozlovsky
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

Re: Foreign Key query question

2009-04-10 Thread Malcolm Tredinnick
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

Re: Foreign Key query question

2009-04-10 Thread nikita kozlovsky
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" ?

Re: Foreign Key query question

2009-03-08 Thread Malcolm Tredinnick
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

Re: Foreign Key query question

2009-03-08 Thread Christoph Wegscheider
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,  

Re: Foreign Key query question

2009-03-08 Thread Daniel Roseman
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: >

Foreign Key query question

2009-03-08 Thread Christoph Wegscheider
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 =

Re: django query question

2009-02-27 Thread Alex Gaynor
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

django query question

2009-02-27 Thread Bobby Roberts
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?

Re: Q query question

2008-04-23 Thread bobhaugen
> 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

Re: Q query question

2008-04-23 Thread bobhaugen
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

Re: Q query question

2008-04-23 Thread Malcolm Tredinnick
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)) > >

Re: Q query question

2008-04-23 Thread bobhaugen
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

Q query question

2008-04-23 Thread bobhaugen
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

Re: second query question

2007-08-28 Thread Tim Chase
> 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. > >

Re: second query question

2007-08-28 Thread r_f_d
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

second query question

2007-08-28 Thread James Tauber
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 =

RESOLVED: Re: Query Question ...

2007-05-23 Thread ZebZiggle
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')

Re: Quick Query Question

2007-05-15 Thread Jeremy Dunck
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): >

Quick Query Question

2007-05-15 Thread Collin Anderson
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

Re: Re: Database query question

2006-09-18 Thread James Bennett
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

Re: Database query question

2006-09-18 Thread Tom Smith
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

Re: Database query question

2006-09-18 Thread Tom Smith
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

Re: Re: Database query question

2006-09-18 Thread James Bennett
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

Re: Database query question

2006-09-18 Thread Michael Radziej
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: >

Re: Database query question

2006-09-18 Thread Tom Smith
> 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

Re: Re: Database query question

2006-09-16 Thread Russell Keith-Magee
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

Re: Database query question

2006-09-16 Thread Tom Smith
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

Re: Database query question

2006-09-16 Thread Malcolm Tredinnick
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

Database query question

2006-09-16 Thread Tom Smith
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