Complex Query

2022-11-20 Thread sebasti...@gmail.com
Hello Guys, you find my question in attachment because tabs in tables are not shown when i send it in gmail. Please help me on my question who make i a complex query. Thanks in advance -- You received this message because you are subscribed to the Google Groups "Django users&q

Re: Replicating complex query with two dense_rank() functions using ORM

2020-11-04 Thread Simon Charette
This is unfortunately not possible to do through the ORM right now due to lack of support for filtering against window expressions[0] Until this ticket is solved you'll have to rely on raw SQL. Cheers, Simon [0] ticket https://code.djangoproject.com/ticket/28333 Le mercredi 4 novembre 2020 à

Re: Replicating complex query with two dense_rank() functions using ORM

2020-11-04 Thread Ramon NHB
Hi, In Django queryset you can query PuzzleAnswer, filter by author (assuming that is the user), order_by('created)' and return the created dates only: values_list('created', flat=True). Then take the len() of that list and check the [0] and [-1] entries for first and last date. The rest is

Replicating complex query with two dense_rank() functions using ORM

2020-11-03 Thread Brad Buran
I have a "puzzle of the day" that users can answer. I track the puzzle of the day using the Puzzle model. I track the answers using the PuzzleAnswer model. I would like to calculate the number of consecutive puzzles a particular user (i.e., the author) gets right in a row. The current SQL I

Re: Complex query on inner join - case for __ne?

2019-04-15 Thread nm
I've only had a quick look at your problem, but looks like maybe this section of the Django documentation could be useful: https://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships On Friday, 12 April 2019 15:10:59 UTC+2, Michael Thomas wrote: > > Hello

Re: Complex query on inner join - case for __ne?

2019-04-12 Thread Michael Thomas
Naimur: I am - that SQL was in response to Aldian's question :) On Fri, Apr 12, 2019 at 8:23 PM naimur rahman wrote: > use ORM istead of SQL > > On Fri, Apr 12, 2019, 7:42 PM Michael Thomas < > michael.thomas.s...@gmail.com> wrote: > >> SELECT >> "app_foo"."id", >> "app_foo"."name" >>

Re: Complex query on inner join - case for __ne?

2019-04-12 Thread naimur rahman
use ORM istead of SQL On Fri, Apr 12, 2019, 7:42 PM Michael Thomas wrote: > SELECT > "app_foo"."id", > "app_foo"."name" > FROM "app_foo" > INNER JOIN "app_bar" ON ( > "app_foo"."id" = "app_bar"."foo_id" > ) > WHERE ( > NOT ( > "app_foo"."id" IN ( > SELECT >

Re: Complex query on inner join - case for __ne?

2019-04-12 Thread Michael Thomas
SELECT "app_foo"."id", "app_foo"."name" FROM "app_foo" INNER JOIN "app_bar" ON ( "app_foo"."id" = "app_bar"."foo_id" ) WHERE ( NOT ( "app_foo"."id" IN ( SELECT U1."foo_id" FROM "app_bar" U1 WHERE U1."attribute_1" = 1

Re: Complex query on inner join - case for __ne?

2019-04-12 Thread Aldian Fazrihady
What's the result of print(Foo.objects.exclude(bar__attribute=1).filter( bar__attribute_2=2).query) On Fri, 12 Apr 2019, 20:10 Michael Thomas, wrote: > Hello everyone, > > I've run into what I believe is a limitation of the ORM that other people > must be dealing with somehow, but I can't seem

Complex query on inner join - case for __ne?

2019-04-12 Thread Michael Thomas
Hello everyone, I've run into what I believe is a limitation of the ORM that other people must be dealing with somehow, but I can't seem to figure out a sensible solution. I think it's easiest to describe the problem with code. For the following models: class Foo(models.Model): name =

Re: Getting complex query set with a many to many relationship in django

2018-02-23 Thread Andy
If you want to have Articles then get Article.objects.filter(section=xy).oder_by('section__order') Am Donnerstag, 22. Februar 2018 20:47:31 UTC+1 schrieb James Farris: > > I am trying to *get all article objects that are part of a section* in an > edition that is in an issue. I am stumped, even

Getting complex query set with a many to many relationship in django

2018-02-22 Thread James Farris
I am trying to *get all article objects that are part of a section* in an edition that is in an issue. I am stumped, even after looking at the documentation for django 2.x I can get all

Re: Complex query, queryset.query.alias_map and query changes

2016-09-23 Thread Felipe Prenholato
Yeah, I know :\, but still maybe someone have a good idea :), lot of people still using old Django versions. I tried the expressions, the `F()` but it not worked well and I had no time to debug why, but in next weeks I'll probably create a slug field to compare directly. I post here if have

Re: Complex query, queryset.query.alias_map and query changes

2016-09-23 Thread Tim Graham
Not sure, this is using lots of private API and QuerySet.extra() which is discourage these days. I'm afraid you won't get much help for unsupported Django versions. After you upgrade to Django 1.9+, hopefully you can construct your query using the new expressions API!

Complex query, queryset.query.alias_map and query changes

2016-09-23 Thread Felipe Prenholato
Hello folks! I have a complex queryset here that do joins in at least 8 tables. The query is fast, but has use of Postgresql `concat` method, and to make it have correct aliases I'm using `qs.query.alias_map` where qs is my queryset instance: def my_complex_queryset(self): qs =

Re: Django model complex query ( use table A.column1 as parameter to query result from table B)

2014-10-21 Thread Vijay Khemlani
I think you are trying to establish a many-to-many relationship between the models, that way it would be like this poiRes = models.ManyToManyField(POIS) and the candidatePois is unnecessary in that case. On Tue, Oct 21, 2014 at 3:16 PM, zhang rock wrote: > Hi All, >

Django model complex query ( use table A.column1 as parameter to query result from table B)

2014-10-21 Thread zhang rock
Hi All, I have a question: how to use table A.column1 as parameter to query result from table B? I have two tables : 1. UserStay idcandidatePoiIdsselectedPoiId 1101,102,103 100 2. POIs id name address 100 starbuck 100 main st, 101 mcdonalds 101

How to convert SQL Complex QUERY to django QUERY

2014-03-18 Thread Shoaib Ijaz
I am trying to convert sql query to django query but failed to do this, can anyone help me select id,name,round(value::numeric,2) as value, st_transform(geometry, 3857) as geometry from net_rest where state_id in (1,2) and name = 'height' union (select

Re: Complex query reduction

2013-11-08 Thread Javier Guerra Giraldez
On Fri, Nov 8, 2013 at 1:44 AM, Robin St.Clair wrote: > The last time I checked the use of IN, all the records from the database in > the query were brought back to the workstation, rather than being processed > on the backend and only the results returned to the workstation.

Re: Complex query reduction

2013-11-08 Thread François Schiettecatte
I am pretty sure the IN() performance issue in MySQL was fixed 5.5, and 5.6/5.7 certainly don't have an issue with IN() whether you use a bunch of values or a subquery. Cheers François On Nov 8, 2013, at 2:15 AM, akaariai wrote: > On Friday, November 8, 2013 8:44:09 AM

Re: Complex query reduction

2013-11-07 Thread akaariai
On Friday, November 8, 2013 8:44:09 AM UTC+2, Robin St.Clair wrote: > > Anssi > > The last time I checked the use of IN, all the records from the database > in the query were brought back to the workstation, rather than being > processed on the backend and only the results returned to the

Re: Complex query reduction

2013-11-07 Thread Robin St . Clair
Anssi The last time I checked the use of IN, all the records from the database in the query were brought back to the workstation, rather than being processed on the backend and only the results returned to the workstation. Have there been changes that carry out the entire query on the

Re: Complex query reduction

2013-11-07 Thread akaariai
On Sunday, November 3, 2013 1:48:07 PM UTC+2, Robin St.Clair wrote: > > *IN* > >- if using Django avoid the IN operation at all costs > > > If there are potentially more than 15 items in the list, rework the IN as > a JOIN against whatever the source of the keys is > I don't necessarily

Re: Complex query reduction

2013-11-04 Thread Apostolos Bessas
On Sat, Nov 2, 2013 at 4:50 PM, Daniele Procida wrote: > > But, the real killer is the combination of ordering (in the queryset or on > the model, it doesn't matter) with the distinct() - as soon as one is removed > from the equation, the execution time drops to around 250ms.

RE: Complex query reduction

2013-11-03 Thread Robin St . Clair
end coders didn't consider the DBMS to be importantDate: Sun, 3 Nov 2013 02:37:09 -0800 From: akaar...@gmail.com To: django-users@googlegroups.com Subject: Re: Complex query reduction You should rewrite the query into a form that doesn't require distinct. In general, when you see a query that has

Re: Complex query reduction

2013-11-03 Thread akaariai
You should rewrite the query into a form that doesn't require distinct. In general, when you see a query that has joins and DISTINCT, that should be an alarm bell that something isn't written correctly in the query. Unfortunately Django's ORM generates such queries, and that isn't easy to fix

Re: Complex query reduction

2013-11-02 Thread Daniele Procida
On Fri, Nov 1, 2013, Javier Guerra Giraldez wrote: >have you tried eliminating the second IN relationship? something like > >entities = entity.get_descendants() > >items = BibliographicRecord.objects.filter

Re: Complex query reduction

2013-11-01 Thread Javier Guerra Giraldez
On Fri, Nov 1, 2013 at 12:45 PM, Daniele Procida wrote: > In practice I use some tweaks (such as values_list) to speed this up, and > caching, but the fundamental pattern is the same. It's slow, because there > are 30 thousand BibliographicRecords. the total number of

Complex query reduction

2013-11-01 Thread Daniele Procida
I have been exploring a rather complex query: # get all the MPTT descendants of entity entities = entity.get_descendants() # get all the Researchers in these Entities researchers = Researcher.objects.filter(person__member_of__entity__in=entities) # get all the BibliographicRecords

Re: Complex query

2013-09-09 Thread Drew Ferguson
On Mon, 9 Sep 2013 06:57:46 -0700 (PDT) Yegor Roganov wrote: > Thanks for you replies. > But I wonder how real production web sites deal with this problem. The > problem is that I want to display about 30 topics per page which would > result in 30+1 queries if implemented

Re: Complex query

2013-09-09 Thread Yegor Roganov
Thanks for you replies. But I wonder how real production web sites deal with this problem. The problem is that I want to display about 30 topics per page which would result in 30+1 queries if implemented naively. If I write the required query in raw SQL, it should be faster, but probably not

Re: Complex query

2013-09-09 Thread akaariai
On Monday, September 9, 2013 12:13:09 AM UTC+3, Yegor Roganov wrote: > > I found out this is a so called "top n per group" problem and it's not > that easy to implement in django. Maybe someone could help me to find > another way (for example, alter the schema in some way)? > This is something

Re: Complex query

2013-09-08 Thread Jani Tiainen
Problem is that you have to be able to express it in SQL. And thus ther is not much you can do in SQL to get what you actually wanted. Considering amount of the data fetched - it's relatively low query count and unless you're hitting very busy site you wont notice much of difference doing this

Re: Complex query

2013-09-08 Thread Yegor Roganov
I found out this is a so called "top n per group" problem and it's not that easy to implement in django. Maybe someone could help me to find another way (for example, alter the schema in some way)? -- You received this message because you are subscribed to the Google Groups "Django users"

Re: Complex query

2013-09-08 Thread Nick Apostolakis
On 08/09/2013 08:17 μμ, Yegor Roganov wrote: I'm developing a forum and my db schema is roughly equivalent to the following: class Topic(models.Model): head = models.CharField() body = models.TextField() created = models.DateTimeField(auto_now_add=True) class Post(models.Model):

Complex query

2013-09-08 Thread Yegor Roganov
I'm developing a forum and my db schema is roughly equivalent to the following: class Topic(models.Model): head = models.CharField() body = models.TextField() created = models.DateTimeField(auto_now_add=True) class Post(models.Model): body = models.TextField() topic =

How do I construct a queryset for this complex query?

2012-05-19 Thread Devin
I've got a complex query that uses a combination of Q objects and qargs to produce the following query: Note the T4 alias...this is central to the question. SELECT `t_answer`.`id`, `t_answer`.`question_id`, `t_answer`.`survey_id`, `t_answer`.`content_type_id`, `t_intanswer`.`answer_ptr_id

Re: Need help on a (maybe complex) query with aggregate/annotate

2012-02-22 Thread Enrico
Works like a charm. Thanks! Ciao Enrico On Feb 21, 11:06 pm, Michael Elkins wrote: > On Tue, Feb 21, 2012 at 01:10:28PM -0800, Enrico wrote: > >But your query counts all the books, even the bad ones. I only need to > >count the good ones... > > >For example, if my books are:

Re: Need help on a (maybe complex) query with aggregate/annotate

2012-02-21 Thread Michael Elkins
On Tue, Feb 21, 2012 at 01:10:28PM -0800, Enrico wrote: But your query counts all the books, even the bad ones. I only need to count the good ones... For example, if my books are: 1. name: LOTR, rating: 10, publisher: A ... 2. name: ASOIAF, rating: 10, publisher: A ... 3. name: Twilight,

Re: Need help on a (maybe complex) query with aggregate/annotate

2012-02-21 Thread Enrico
Thanks Micheal for the response! But your query counts all the books, even the bad ones. I only need to count the good ones... For example, if my books are: 1. name: LOTR, rating: 10, publisher: A ... 2. name: ASOIAF, rating: 10, publisher: A ... 3. name: Twilight, rating 1, publisher: B ...

Re: Need help on a (maybe complex) query with aggregate/annotate

2012-02-21 Thread Michael Elkins
On Feb 21, 6:11 am, Enrico wrote: > This query: > Publisher.objects.filter(book__rating__gt=3.0).annotate(num_books=Count('bo > ok')) > returns all the publishers with at least one good book (ranked > 3) > with annotated the number of good books for each publisher. > > How can

Need help on a (maybe complex) query with aggregate/annotate

2012-02-21 Thread Enrico
I'm having a bit of hard time with aggregation. For simplicity's sake consider the models available in the aggregation docs: https://docs.djangoproject.com/en/1.3/topics/db/aggregation/# This query: Publisher.objects.filter(book__rating__gt=3.0).annotate(num_books=Count('book')) returns all the

Re: need help with calling following complex query

2011-07-11 Thread Roshan Mathews
On Mon, Jul 11, 2011 at 10:36, Venkatraman S wrote: > Raw-sql and the snippet provided by me would end up generating the same sql. > > One advantage of my snippet is, if your db does not support sin/cos > functions(like sqlite3), > then you can go ahead defining funcs which

Re: need help with calling following complex query

2011-07-11 Thread Venkatraman S
On Mon, Jul 11, 2011 at 10:36 PM, Jonas Geiregat wrote: > > > > results.extra(select={ > > 'distance': > '(acos(sin(latitude)*sin(%(latitude)f)+cos(latitude)*cos(%(latitude)f)*cos(%(longitude)f-longitude)))' > % { > >

Re: need help with calling following complex query

2011-07-11 Thread Venkatraman S
On Tue, Jul 12, 2011 at 4:36 AM, sanket wrote: > Thanks @Venkatraman, I really appreciate your help. > ability to create a function is pretty cool. > Thanks. Actually, i stumbled on this solution due to my use case - i test all my apps in sqlite3 and then move to other

Re: need help with calling following complex query

2011-07-11 Thread sanket
Thanks @Venkatraman, I really appreciate your help. ability to create a function is pretty cool. Thanks again, sanket On Jul 11, 1:06 pm, Jonas Geiregat wrote: > > results.extra(select={ > >                             'distance': > >

Re: need help with calling following complex query

2011-07-11 Thread Jonas Geiregat
> > results.extra(select={ > 'distance': > '(acos(sin(latitude)*sin(%(latitude)f)+cos(latitude)*cos(%(latitude)f)*cos(%(longitude)f-longitude)))' > % { > 'latitude': latitude, > 'longitude': longitude

Re: need help with calling following complex query

2011-07-11 Thread Cal Leeming [Simplicity Media Ltd]
Thats pretty cool, I didnt know you could do create function. Will check this out later :) On 11 Jul 2011 06:06, "Venkatraman S" wrote: > On Mon, Jul 11, 2011 at 10:02 AM, sanket wrote: > >> I think I would go ahead with executing the raw SQL in this

Re: need help with calling following complex query

2011-07-10 Thread Venkatraman S
On Mon, Jul 11, 2011 at 10:02 AM, sanket wrote: > I think I would go ahead with executing the raw SQL in this case. > The solution by @Venatraman looks interesting too. I would give it a > try. > Raw-sql and the snippet provided by me would end up generating the same

Re: need help with calling following complex query

2011-07-10 Thread sanket
Thanks all for the help, I really appreciate it. I think I would go ahead with executing the raw SQL in this case. The solution by @Venatraman looks interesting too. I would give it a try. I might write a stored procedure if I start getting performance issues if data starts growing. Thanks

Re: need help with calling following complex query

2011-07-10 Thread Venkatraman S
On Mon, Jul 11, 2011 at 7:10 AM, Cal Leeming [Simplicity Media Ltd] < cal.leem...@simplicitymedialtd.co.uk> wrote: > +1 on raw SQL in this instance. Not exactly, using ORM is pretty easy too. You would do something like this: results.extra(select={ 'distance':

Re: need help with calling following complex query

2011-07-10 Thread Cal Leeming [Simplicity Media Ltd]
+1 on raw SQL in this instance. On Mon, Jul 11, 2011 at 2:36 AM, Jian Chang wrote: > Using raw sql is a better idea > > > 2011/7/11 Jonas Geiregat > >> >> >> In order to find the places in near by area I want to make following >> mysql query. but I am

Re: need help with calling following complex query

2011-07-10 Thread Jian Chang
Using raw sql is a better idea 2011/7/11 Jonas Geiregat > > > In order to find the places in near by area I want to make following > mysql query. but I am not sure how should I translate it using django > models and managers. > > > You could execute the raw sql query string,

Re: need help with calling following complex query

2011-07-10 Thread Jonas Geiregat
> > > In order to find the places in near by area I want to make following > mysql query. but I am not sure how should I translate it using django > models and managers. You could execute the raw sql query string, see: https://docs.djangoproject.com/en/dev/topics/db/sql/ for more information

need help with calling following complex query

2011-07-10 Thread sanket
Hey All, I am quite new to Django and recently started using django for developing a location based service. In order to find the places in near by area I want to make following mysql query. but I am not sure how should I translate it using django models and managers. orig.lat = x orig.lon = y

Re: Complex Query help - get items from the org to which the user belongs

2011-07-07 Thread Venkatraman S
On Thu, Jul 7, 2011 at 3:49 PM, DrBloodmoney wrote: > On Thu, Jul 7, 2011 at 12:04 AM, Venkatraman S wrote: > > I am doing some bechmarking on the performance of both the versions of > the > > query: > > 1. > > >

Re: Complex Query help - get items from the org to which the user belongs

2011-07-07 Thread DrBloodmoney
On Thu, Jul 7, 2011 at 12:04 AM, Venkatraman S wrote: > I am doing some bechmarking on the performance of both the versions of the > query: > 1. > Item.objects.filter(created_by__employees__org__in=u.employees_set.all().values_list('org')) > and > 2.

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Venkatraman S
I am doing some bechmarking on the performance of both the versions of the query: 1. Item.objects.filter(created_by__employees__org__in=u.employees_set.all().values_list('org')) and 2. Items.objects.extra(where=['created_by_id in (select e.user_id from myapp_employees e, myapp_organization o where

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Venkatraman S
On Wed, Jul 6, 2011 at 8:09 PM, Marc Aymerich wrote: > I swear this time it will work! > > Item.objects.filter(created_by__employees__org__in=u.employees_set.all().values_list('org')) > > I cried on seeing this ;) Thanks a tonne. Guess this will go into the django hall of

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Marc Aymerich
On Wed, Jul 6, 2011 at 2:46 PM, Venkatraman S wrote: > > > On Wed, Jul 6, 2011 at 2:10 PM, Marc Aymerich wrote: >> >> This one should work: >> Items.objects.filters(created_by__employee__org=A.org) > > Nope. Emp has a FK for User, not the other way round.

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Tom Evans
On Wed, Jul 6, 2011 at 2:40 PM, akaariai wrote: > Maybe this? > > user = current_user > user_org_employees = Employees.objects.filter(org=user.org) > user_org_items = > Items.objects.filter(created_by__in=user_org_employees) > No, users can belong to multiple organizations,

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread akaariai
On Jul 5, 10:06 pm, Venkatraman S wrote: > I tried asking around in IRC, and stumbled on a few possible solutions, > would be great if someone shed some more light: > > I have the following models: > > class Organization(models.Model): >   name                =

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Venkatraman S
On Wed, Jul 6, 2011 at 2:10 PM, Marc Aymerich wrote: > This one should work: > Items.objects.filters(created_by__employee__org=A.org) > Nope. Emp has a FK for User, not the other way round. -- You received this message because you are subscribed to the Google Groups

Re: Complex Query help - get items from the org to which the user belongs

2011-07-06 Thread Marc Aymerich
On Wed, Jul 6, 2011 at 4:46 AM, Venkatraman S wrote: > > On Wed, Jul 6, 2011 at 2:26 AM, Marc Aymerich wrote: > >> Say there are 3 Users in an org : A, B and C with each creating 3,4,5 >> items respectively, and 'A' is the current user; then i need a

Re: Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Venkatraman S
On Wed, Jul 6, 2011 at 8:39 AM, Venkatraman S wrote: > > On Wed, Jul 6, 2011 at 12:36 AM, Venkatraman S wrote: > >> I tried asking around in IRC, and stumbled on a few possible solutions, >> would be great if someone shed some more light: >> >> I have the

Re: Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Venkatraman S
On Wed, Jul 6, 2011 at 12:36 AM, Venkatraman S wrote: > I tried asking around in IRC, and stumbled on a few possible solutions, > would be great if someone shed some more light: > > I have the following models: > > class Organization(models.Model): > name=

Re: Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Venkatraman S
On Wed, Jul 6, 2011 at 2:26 AM, Marc Aymerich wrote: > Say there are 3 Users in an org : A, B and C with each creating 3,4,5 items > respectively, and 'A' is the current user; then i need a query which returns > all these items(i.e, 12 items) when i supply A.. > >

Re: Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Marc Aymerich
On Tue, Jul 5, 2011 at 9:06 PM, Venkatraman S wrote: > I tried asking around in IRC, and stumbled on a few possible solutions, > would be great if someone shed some more light: > > I have the following models: > > class Organization(models.Model): > name=

Complex Query help - get items from the org to which the user belongs

2011-07-05 Thread Venkatraman S
I tried asking around in IRC, and stumbled on a few possible solutions, would be great if someone shed some more light: I have the following models: class Organization(models.Model): name= models.CharField(max_length=100, blank=False) class Employees(models.Model): org

Re: complex query

2011-07-04 Thread Andre Terra
Hello First, I must recommend that you use django-taggit, simpletag or any other tagging app, otherwise you'll just be reinventing the wheel. As for your question, you should read the aggregation docs. I don't have the link handy, but this should be correct: http://django.me/aggregation

complex query

2011-07-03 Thread Jonas Geiregat
Hello, I have the following models class Book(models.Model): author = models.ManyToManyField(Author) pub_date = models.DateTimeField() ... class Author(models.Model): tag = models.ManyToManyField(Tag) class Tag(models.Model): name =

Re: Complex query

2011-03-29 Thread gontran
Now that I changed my model, the query is a little bit different. So, my models: UserProfile(models.Model): user = models.OneToOneField(User) company = models.ForeignKey(Company) Company(models.Model): ...some fields... Product(models.Model): ...some fields...

Re: Complex query

2011-03-29 Thread Kenneth Gonsalves
On Tue, 2011-03-29 at 01:17 -0700, bruno desthuilliers wrote: > On 29 mar, 09:33, Kenneth Gonsalves wrote: > > Product is not linked to them - they are linked to Product. > > Sorry but I dont see the point here - you can follow a relationship > both way. pointless

Re: Complex query

2011-03-29 Thread gontran
Hi Bruno, yes you're right. I should change my model in the way you mentioned it. I saw that a couple of minutes ago. And to answer to my initial question, I might have found the answer. The query would be: news = News.objects.filter(related_products__productlicence__in =

Re: Complex query

2011-03-29 Thread bruno desthuilliers
On 29 mar, 09:11, gontran wrote: > Hi everybody, > > considering the folowing models: > > UserProfile(models.Model): >     user = models.OneToOneField(User) >     company = models.ForeignKey(Company) > > Company(models.Model): >     product_licences =

Re: Complex query

2011-03-29 Thread bruno desthuilliers
On 29 mar, 09:33, Kenneth Gonsalves wrote: > Product is not linked to them - they are linked to Product. Sorry but I dont see the point here - you can follow a relationship both way. -- You received this message because you are subscribed to the Google Groups "Django

Re: Complex query

2011-03-29 Thread gontran
Ok. I 'll try again Thank you very much for your consideration. Regards, Gontran On 29 mar, 09:33, Kenneth Gonsalves wrote: > Product is not linked to them - they are linked to Product. I do not > think you can do it in one query because there are ManyToMany fields >

Re: Complex query

2011-03-29 Thread Kenneth Gonsalves
Product is not linked to them - they are linked to Product. I do not think you can do it in one query because there are ManyToMany fields which have to be retrieved and then you have to iterate over them. Certainly more than one query. On Tue, 2011-03-29 at 00:24 -0700, gontran wrote: > Yes:

Re: Complex query

2011-03-29 Thread gontran
Yes: ProductLicence and News On 29 mar, 09:19, Kenneth Gonsalves wrote: > On Tue, 2011-03-29 at 00:11 -0700, gontran wrote: > > UserProfile(models.Model): > >     user = models.OneToOneField(User) > >     company = models.ForeignKey(Company) > > > Company(models.Model): >

Re: Complex query

2011-03-29 Thread Kenneth Gonsalves
On Tue, 2011-03-29 at 00:11 -0700, gontran wrote: > UserProfile(models.Model): > user = models.OneToOneField(User) > company = models.ForeignKey(Company) > > Company(models.Model): > product_licences = models.manyToManyField(ProductLicence) > > Product(models.Model): > ...some

Complex query

2011-03-29 Thread gontran
Hi everybody, considering the folowing models: UserProfile(models.Model): user = models.OneToOneField(User) company = models.ForeignKey(Company) Company(models.Model): product_licences = models.manyToManyField(ProductLicence) Product(models.Model): ...some fields...

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

Complex Query Optimization

2009-09-12 Thread Phil
I am trying to minimize the database hits. Take this example... from django.contrib.auth.models import User class Group(models.Model): # a bunch of fields here user = models.ForeignKey(User, related_name="groups") class Member(models.Model): # a bunch of fields here user =

complex query - howto do with django orm?

2009-09-11 Thread tom
Hi all, i have a complex query and want to do this query with the django orm. I already use django, but the raw-sql-way: def get_windenergy_data(self, windspeed_channel, winddirection_channel, project_id, logger_serial): from django.db import connection cursor

Change the where clause in a complex query involving a model with a self many to many

2009-08-24 Thread Jacob Fenwick
I have a hierarchy of models where the bottom object in the hierarchy has a many to many relationship to itself. Here are my models and views: models.py class Bar(models.Model): name = models.CharField(max_length=200) class BarPart(models.Model): bar = models.ForeignKey(Bar) name =

Re: Complex query in model manager

2009-08-23 Thread CrabbyPete
or another words can I use a Q object in a model manager? On Aug 23, 12:05 am, CrabbyPete wrote: > I have the following code in model manager > > class SpotMessageManager(models.Manager): > >       def for_user(self, user, start = 0, end = None, friends ): >            

Complex query in model manager

2009-08-22 Thread CrabbyPete
I have the following code in model manager class SpotMessageManager(models.Manager): def for_user(self, user, start = 0, end = None, friends ): messages = self.filter(user = user).order_by ('date_added').reverse() ... friends is a list of users, and I want the

Re: Parsing a complex query with many parentheses, ORs, ANDs, and (hopefully) NOTs

2008-11-21 Thread Michael Keselman
On Nov 21, 2008, at 11:46 PM, Malcolm Tredinnick wrote: > > > On Fri, 2008-11-21 at 22:37 -0500, Michael Keselman wrote: >> Hello, >> >> http://pastie.org/private/xvqf5tgjnimiolakhawgg (relevant code) >> >> Django's QuerySets allow you to do ORs (unions) pretty nicely with >>

Re: Parsing a complex query with many parentheses, ORs, ANDs, and (hopefully) NOTs

2008-11-21 Thread Malcolm Tredinnick
On Fri, 2008-11-21 at 22:37 -0500, Michael Keselman wrote: > Hello, > > http://pastie.org/private/xvqf5tgjnimiolakhawgg (relevant code) > > Django's QuerySets allow you to do ORs (unions) pretty nicely with > Model.manager.filter(Q(...) | Q(...)). However, ANDs don't work quite > as nicely

Parsing a complex query with many parentheses, ORs, ANDs, and (hopefully) NOTs

2008-11-21 Thread Michael Keselman
Hello, http://pastie.org/private/xvqf5tgjnimiolakhawgg (relevant code) Django's QuerySets allow you to do ORs (unions) pretty nicely with Model.manager.filter(Q(...) | Q(...)). However, ANDs don't work quite as nicely in my situation because I want AND to do what

Re: complex query in limit_choices_to

2007-11-24 Thread leotr
On database level that should be done by UNIQUE constraints. And your problem should be made on form level. read about ChoiceField in newforms documentation --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django

complex query in limit_choices_to

2007-11-23 Thread Kenneth Gonsalves
hi, I have two models called Child and Sponsor. There is a model called Sponsorship which has foreign keys to Child and Sponsor. For the foreign key to Child, I want to limit choices to all those children who are *not* already a foreign key to sponsorship and who are active. This is the

Re: how to do complex query which filters on method not database field

2006-11-06 Thread Ivan Sagalaev
Rachel Willmer wrote: > I have a complicated query which should return the subset of a table > whose objects match one of several conditions. > > What's the easiest way of doing this, given that I can't just do a SQL > statement, because some of the conditions require me to feed the > object's

how to do complex query which filters on method not database field

2006-11-06 Thread Rachel Willmer
I have a complicated query which should return the subset of a table whose objects match one of several conditions. What's the easiest way of doing this, given that I can't just do a SQL statement, because some of the conditions require me to feed the object's values into a function to evaluate