Re: Django + Django REST Framework SQL query response handling and serialization is very, very slow - yet not a “N+1” problem

2017-06-11 Thread Alceu Rodrigues de Freitas Junior
easily (I'm assuming you have a view to list all those instances for those Models). Em 11/06/2017 13:15, Miika Huusko escreveu: Thanks for response! Yep, timing with "time" is not the best way to go to compare SQL query times. The reason I added that "time" test is that

Re: Django + Django REST Framework SQL query response handling and serialization is very, very slow - yet not a “N+1” problem

2017-06-11 Thread Miika Huusko
Thanks for response! Yep, timing with "time" is not the best way to go to compare SQL query times. The reason I added that "time" test is that in Stack Overflow I was asked to confirm that data transfer is not factor here. I timed SQL queries with "EXPLAIN ANA

Re: Django + Django REST Framework SQL query response handling and serialization is very, very slow - yet not a “N+1” problem

2017-06-11 Thread Alceu Rodrigues de Freitas Junior
on a Perl related blog, the concepts on the post are applicable everywhere. Em 11/06/2017 07:06, Miika Huusko escreveu: I have a performance problem with Django + Django REST Framework. The problem is that it takes Django very, very long time to handle SQL query response + DRF serialization take

Re: Django + Django REST Framework SQL query response handling and serialization is very, very slow - yet not a “N+1” problem

2017-06-11 Thread Alceu Rodrigues de Freitas Junior
see, you want to get 10k to 50k items... that's a lot (to serialize too). Em 11/06/2017 07:06, Miika Huusko escreveu: I have a performance problem with Django + Django REST Framework. The problem is that it takes Django very, very long time to handle SQL query response + DRF serialization take

Django + Django REST Framework SQL query response handling and serialization is very, very slow - yet not a “N+1” problem

2017-06-11 Thread Miika Huusko
I have a performance problem with Django + Django REST Framework. The problem is that it takes Django very, very long time to handle SQL query response + DRF serialization take quite some time also. It happens when there are ManyToMany or OneToMany relations and nested objects. Sounds like &q

Re: Possible bug - Incorrect escaping in Django SQL query

2017-06-02 Thread Tim Graham
ny testing of TruncDay with Value(). Is there a difference between the query you're trying to construct and MyModel.objects.filter(created__lt=timezone.now().date()) ? On Friday, June 2, 2017 at 5:15:23 AM UTC-4, Michal Petrucha wrote: > > On Thu, Jun 01, 2017 at 02:29:17AM -0700, Roshan Raghupath

Re: Possible bug - Incorrect escaping in Django SQL query

2017-06-02 Thread Michal Petrucha
On Thu, Jun 01, 2017 at 02:29:17AM -0700, Roshan Raghupathy wrote: > Hi, > I came across an issue yesterday. Post on stackoverflow > <https://stackoverflow.com/questions/44287443/incorrect-escaping-in-django-sql-query> > > On further investigation today, I think I found th

Possible bug - Incorrect escaping in Django SQL query

2017-06-01 Thread Roshan Raghupathy
Hi, I came across an issue yesterday. Post on stackoverflow <https://stackoverflow.com/questions/44287443/incorrect-escaping-in-django-sql-query> On further investigation today, I think I found the source of the issue. It's this line <https://github.com/django/django/blob/master/

Re: count from multiple tables in a single query?

2017-06-01 Thread Melvyn Sopacua
t this results in two different queries to the > database. Can it be done with a single query call? Why is that a concern? This isn't the kind of thing to optimize. Query optimization is about loops and relations. Not about getting information you need - it comes at a price. Have you timed what yo

Re: count from multiple tables in a single query?

2017-05-31 Thread James Schneider
On Wed, May 31, 2017 at 3:01 PM, Alceu Rodrigues de Freitas Junior < alceu.freitas...@gmail.com> wrote: > Hi James, > > I'm curious... why dropping down from the ORM and doing a single query > wouldn't be portable? > > I understand that it would happen if you use some

Re: count from multiple tables in a single query?

2017-05-31 Thread Alceu Rodrigues de Freitas Junior
Hi James, I'm curious... why dropping down from the ORM and doing a single query wouldn't be portable? I understand that it would happen if you use some kind of stored procedure in the DB, but I guess a single ANSI SQL would do it. Thanks! - Alceu Em 31/05/2017 17:29, James Schneider

Re: count from multiple tables in a single query?

2017-05-31 Thread 'Abraham Varricatt' via Django users
PM > *To:* Django users > *Subject:* count from multiple tables in a single query? > > > > Hello, > > Is it possible to get the count of entries from multiple tables in a > single query call? I'm looking at the official docs on aggregation and I > can't find a

RE: count from multiple tables in a single query?

2017-05-31 Thread Matthew Pava
@googlegroups.com] Sent: Wednesday, May 31, 2017 2:14 PM To: Django users Subject: count from multiple tables in a single query? Hello, Is it possible to get the count of entries from multiple tables in a single query call? I'm looking at the official docs on aggregation and I can't find anything

Re: count from multiple tables in a single query?

2017-05-31 Thread James Schneider
> > > If I want to get the total count from both tables it can be done like this, > > author_count = Author.objects.count() > publisher_count = Publisher.objects.count() > > My concern is that this results in two different queries to the database. > Can it be do

count from multiple tables in a single query?

2017-05-31 Thread 'Abraham Varricatt' via Django users
Hello, Is it possible to get the count of entries from multiple tables in a single query call? I'm looking at the official docs on aggregation and I can't find anything. For example assume I have the following 2 tables, class Author(models.Model): name = models.CharField(max_length=100

Re: Matching query does not exist after a post_data signal, but in fact does exist when visiting the url sent by the query

2017-05-17 Thread Constantine Covtushenko
gt; order to create the good content for each instance of ModelA. When I try to > use a string of the url sending the id parameter, the content field has for > value the source code of the debug page > > (error 500, DoesNotExist at /admin/apptwo/modelb/my_view/ref=76, [76 is &g

Matching query does not exist after a post_data signal, but in fact does exist when visiting the url sent by the query

2017-05-16 Thread François-Xavier Cao
field has for value the source code of the debug page (error 500, DoesNotExist at /admin/apptwo/modelb/my_view/ref=76, [76 is an example] ModelB matching query does not exist. Exception location : /home/me/Desktop/env/lib/python3.5/site-packages/django/db/models/query.py in get, line 385

Re: Aggregating a query while selecting more than grouped by ...

2017-05-14 Thread Bernd Wechner
Todor, Awesome thanks yet again! I think I'm rolling now ;-). Tested it and it looks like it works, pending some rigorous testing. The query looks good though and makes sense to me. Forgive my naivete regarding Group By. I had a thorough think about how I'd build a raw SQL version

Re: Aggregating a query while selecting more than grouped by ...

2017-05-14 Thread Todor Velichkov
There is no `group_by` clause in the ORM, because this will lead to ambiguous queries. Ambiguous query is a query where you have a non-distinct column in the select, that is missing from the group_by clause. Its actually a MySQL fault for allowing it, in other RDBMS you will get an ambiguous

Re: Aggregating a query while selecting more than grouped by ...

2017-05-14 Thread Bernd Wechner
.values('country') .annotate(max_date=Max('book_set__pubdate')) .values('max_date')[:1] ) ) ) But yes I concur this strikes me as a fairly ordinary sort of SQL query in my experience and hence would be nice if it were well documen

Re: Aggregating a query while selecting more than grouped by ...

2017-05-13 Thread Todor Velichkov
ngo> you will probably get: here <https://stackoverflow.com/questions/2111590/how-can-a-do-a-greatest-n-per-group-query-in-django> or here <https://stackoverflow.com/questions/2074514/django-query-that-get-most-recent-objects-from-different-categories> . My approach to this problem, i

Aggregating a query while selecting more than grouped by ...

2017-05-13 Thread Bernd Wechner
of the (one) author in each country that published the last book before a given date. Ostensibly the only option I have is: LatestAuthors = Author.objects.filter(book_set__pubdate__lte=SOMEDATE).values('country').annotate(Max('book_set__pubdate')) That seems to work generating a query that authors

Re: getting error "Project matching query does not exist."

2017-04-15 Thread Camilo Torres
> I have setup existing django project at localsystem and its migrate >>> successfully. >>> after migrate i have run following "python manage.py runserver" to run >>> django project. >>> >>> After that i am getting error message "Pr

Re: getting error "Project matching query does not exist."

2017-04-12 Thread ludovic coues
d its migrate >> successfully. >> after migrate i have run following "python manage.py runserver" to run >> django project. >> >> After that i am getting error message "Project matching query does not >> exist." on terminal and as well

Re: getting error "Project matching query does not exist."

2017-04-12 Thread nitin
lsystem and its migrate > successfully. > after migrate i have run following "python manage.py runserver" to run > django project. > > After that i am getting error message "Project matching query does not > exist." on terminal and as well as browser. >

Re: getting error "Project matching query does not exist."

2017-04-12 Thread nitin
owing "python manage.py runserver" to run > django project. > > After that i am getting error message "Project matching query does not > exist." on terminal and as well as browser. > > Please let me know of what is problem. > > > > Please help me to

Re: getting error "Project matching query does not exist."

2017-04-12 Thread ludovic coues
iguration after looking >> at the entire stack trace. >> >> On Tuesday, April 11, 2017 at 9:52:27 AM UTC-4, ni...@linkites.com wrote: >>> >>> Hi, >>> >>> Previous error solve and thanks for that. >>> >>> now i am getting new error o

Re: getting error "Project matching query does not exist."

2017-04-12 Thread nitin
now. >> >> >> <https://lh3.googleusercontent.com/-F1-7S1-tH9g/WOzfhUOTAWI/AeU/D2GRF3O8AQ8YnThyRRbJ_XUtI5yRYX0lwCLcB/s1600/Screenshot%2Bfrom%2B2017-04-11%2B19-21-51.png> >> >> >> On Tuesday, April 11, 2017 at 4:38:30 PM UTC+5:30, ni...@linkites.com >>

Re: getting error "Project matching query does not exist."

2017-04-11 Thread Camilo Torres
roject at localsystem and its migrate >> successfully. >> after migrate i have run following "python manage.py runserver" to run >> django project. >> >> After that i am getting error message "Project matching query does not >> exist."

Re: getting error "Project matching query does not exist."

2017-04-11 Thread nitin
y runserver" to run > django project. > > After that i am getting error message "Project matching query does not > exist." on terminal and as well as browser. > > Please let me know of what is problem. > > > > Please help me to solve this issue.

Re: getting error "Project matching query does not exist."

2017-04-11 Thread Andréas Kühne
t;> successfully. >>> after migrate i have run following "python manage.py runserver" to run >>> django project. >>> >>> After that i am getting error message "Project matching query does not >>> exist." on terminal and a

Re: getting error "Project matching query does not exist."

2017-04-11 Thread nitin
. >> after migrate i have run following "python manage.py runserver" to run >> django project. >> >> After that i am getting error message "Project matching query does not >> exist." on terminal and as well as browser. >> >> Please

Re: getting error "Project matching query does not exist."

2017-04-11 Thread ludovic coues
at localsystem and its migrate > successfully. > after migrate i have run following "python manage.py runserver" to run > django project. > > After that i am getting error message "Project matching query does not > exist." on terminal and as well as browser. >

getting error "Project matching query does not exist."

2017-04-11 Thread nitin
Hi, I have setup existing django project at localsystem and its migrate successfully. after migrate i have run following "python manage.py runserver" to run django project. After that i am getting error message "Project matching query does not exist." on terminal an

Re: combining ORM and raw SQL in same query

2017-02-21 Thread Larry Martell
pend on raw SQL. > > -Original Message- > From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On > Behalf Of Larry Martell > Sent: Monday, February 20, 2017 3:00 PM > To: django-users@googlegroups.com > Subject: Re: combining ORM and raw SQL in same qu

RE: combining ORM and raw SQL in same query

2017-02-21 Thread Matthew Pava
Martell Sent: Monday, February 20, 2017 3:00 PM To: django-users@googlegroups.com Subject: Re: combining ORM and raw SQL in same query Thanks! On Mon, Feb 20, 2017 at 10:52 AM, m1chael <myk...@gmail.com> wrote: > i did something like this recently using .extra / select

Re: combining ORM and raw SQL in same query

2017-02-20 Thread Larry Martell
rry.mart...@gmail.com> > wrote: >> >> Is there any way to use both the ORM and raw SQL in the same query? >> >> I have an existing app that uses the ORM and now I have a need to add >> SQL like this to the select: >> >> (CASE >> WHEN TRIM(IFNULL

Re: combining ORM and raw SQL in same query

2017-02-20 Thread m1chael
i did something like this recently using .extra / select https://docs.djangoproject.com/en/1.10/ref/models/querysets/#extra On Mon, Feb 20, 2017 at 10:49 AM, Larry Martell <larry.mart...@gmail.com> wrote: > Is there any way to use both the ORM and raw SQL in the same query? &

combining ORM and raw SQL in same query

2017-02-20 Thread Larry Martell
Is there any way to use both the ORM and raw SQL in the same query? I have an existing app that uses the ORM and now I have a need to add SQL like this to the select: (CASE WHEN TRIM(IFNULL(roiname, '')) IN ('', 'None') THEN CONCAT_WS('.', roi_type_id, roi_id) WHEN CONCAT_WS('.', roi_type_id

Re: PostgreSQL get_object_or_404 matching query does not exist when indeed it does?

2017-02-18 Thread Nikoleta Misheva
> I am querying PostgreSQL using *get_object_or_404 * but it throws and >> exception *PairUsers matching query does not exist *and after that *During >> handling of the above exception, another exception >> occurred:django.http.response.Http404: No PairUsers matches the given qu

Re: PostgreSQL get_object_or_404 matching query does not exist when indeed it does?

2017-02-18 Thread Daniel Roseman
On Saturday, 18 February 2017 17:37:49 UTC, Nikoleta Misheva wrote: > > I am querying PostgreSQL using *get_object_or_404 * but it throws and > exception *PairUsers matching query does not exist *and after that *During > handling of the above exception, anoth

PostgreSQL get_object_or_404 matching query does not exist when indeed it does?

2017-02-18 Thread Nikoleta Misheva
I am querying PostgreSQL using *get_object_or_404 * but it throws and exception *PairUsers matching query does not exist *and after that *During handling of the above exception, another exception occurred:django.http.response.Http404: No PairUsers matches the given query *when indeed I

Re: return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login when adding a superuser

2017-02-13 Thread Tim Graham
b/python2.7/site-packages/django/db/backends/utils.py", >> >> line 79, in execute >> return super(CursorDebugWrapper, self).execute(sql, params) >> File >> "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/bac

Re: return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login when adding a superuser

2017-02-13 Thread ludovic coues
> File "/root/udemystuff/test_project/trydjango19/local/lib/ > python2.7/site-packages/django/db/backends/utils.py", line 64, in execute > return self.cursor.execute(sql, params) > File "/root/udemystuff/test_project/trydjango19/local/lib/ > python2.7/si

Re: return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login when adding a superuser

2017-02-12 Thread Adam
return self.cursor.execute(sql, params) File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 323, in execute return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: NOT NULL constrai

Re: return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login when adding a superuser

2017-02-12 Thread Antonis Christofides
project/trydjango19/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", > line 323, in execute > return Database.Cursor.execute(self, query, params) > django.db.utils.IntegrityError: NOT NULL constraint failed: > auth_user.last_login > > > I trie

return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login when adding a superuser

2017-02-12 Thread Adam
Hi everyone, I'm super new to django, I tried to add a superuser and this is the error I got: File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 323, in execute return Database.Cursor.execute(self, que

result of filter query returning empty because of def __unicode__(self)

2017-01-26 Thread Mike08
above there are two lines A and B. Currently Line B is commented and this query works and I get back an object lab_entries= modelNormalLabTest.objects.filter(test_name__test_name="ABC") However if I replace return self.test_name in the model modelLabTestName with this

Re: Query on AppRegistryNotReady: Apps aren't loaded yet error

2017-01-04 Thread Nilesh
Really, I did not face this issue in past. It may be some setup issue. Some app is not registered properly. Check admin.py or settings.py On Wed, Jan 4, 2017 at 3:18 PM, pritesh modi wrote: > Team > > > In VM Django with 1.6 run below code and generate a HTMLreport

Proper way of passing query from form to url in Django class based view

2016-12-12 Thread dsfqce cwfe
I want to learn a proper way of passing query from form to url in Django class based view. I want to retrieve form data in ListView to make query on the model. I'm currently using this, but i feel that there's a better way. class SearchFormView(FormView): form_class = SearchForm

Re: Matching query does not exist when retrieving object by slug

2016-12-10 Thread Antonis Christofides
> self.slug =slugify(self.name,allow_unicode=True) > | > > The problem is when I use a ModelForm to create object, the slug field is set > correctly, but when I use it to look up the object, it returns > "lists.models.DoesNotExist: TopList matching query does not exist" (I tried

Matching query does not exist when retrieving object by slug

2016-12-09 Thread Viet Phuong
is when I use a ModelForm to create object, the slug field is set correctly, but when I use it to look up the object, it returns "lists.models.DoesNotExist: TopList matching query does not exist" (I tried it in the shell): # forms.py class TopListForm(ModelForm): class Meta:

Re: rewrite PostgreSQL query to Django ORM

2016-11-29 Thread Avraham Serour
< artem.bernats...@gmail.com> wrote: > Hello, how to rewrite this PostgreSQL query to Django ORM with no raw SQL ? > > > select * from finance_fund order by((select price from finance_nav where > date='2016-11-08' and fund_id=finance_fund.id)/(select price from > finance_na

rewrite PostgreSQL query to Django ORM

2016-11-29 Thread Artem Bernatskyy
Hello, how to rewrite this PostgreSQL query to Django ORM with no raw SQL ? select * from finance_fund order by((select price from finance_nav where date='2016-11-08' and fund_id=finance_fund.id)/(select price from finance_nav where date='2016-11-07' and fund_id=finance_fund.id)) LIMIT 30; So

Re: Raw query returns 1 row but outputting multiple rows in template

2016-10-06 Thread Andromeda Yelton
What's in the get_digital_client_summary() function? On Thu, Oct 6, 2016 at 6:18 AM, Thomas Brightwell < thomas.brightw...@gmail.com> wrote: > Hi, > > I have a raw query returning one row which is then shown 8 times in the > template. I have debugged and there is

Raw query returns 1 row but outputting multiple rows in template

2016-10-06 Thread Thomas Brightwell
Hi, I have a raw query returning one row which is then shown 8 times in the template. I have debugged and there is only one line when this is executed in the shell and I do a simple for loop print output. So it seems to be something about the template tags? The raw query which definitely only

Re: How to populate a JqGrid in Django with data obtained from a query (queryset)

2016-09-27 Thread João Rodrigues
Thanks for your answer. The project is rather big and I am still not used to Django. I got some help and it has been solved. -- 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

Re: How to populate a JqGrid in Django with data obtained from a query (queryset)

2016-09-25 Thread Gergely Polonkai
Hello, do you already know how to do it without Django, e.g with a static dataset? Because, from the HTML page's view, you will exactly do that. I don't know JqGrid, but I assume it needs an array of objects, like gridData = [ { firstColumn: 1, secondColumn: "data" },

How to populate a JqGrid in Django with data obtained from a query (queryset)

2016-09-25 Thread João Rodrigues
I am working on a small online shop with Django 1.9 and JqGrid Here is a simplification of my models: class Addresses(models.Model): address = models.TextField(db_column='ADDRESS', max_length=2000) city = models.CharField(db_column='CITY', max_length=400, blank=True,

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

2016-09-23 Thread Felipe Prenholato
com>: > 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 ex

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! https

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 = self.filter

Re: Query annotation with date difference

2016-09-04 Thread Peter of the Norse
com> wrote:Sorry, I did not specify.I have been using 'Postgresql' with 'psycopg2 v.2.6.2'.They gave me those results.Also here is a sql query given from log:SELECT "test_app_entity"."id", "test_app_entity"."due_date", "test_app_entity"."

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-31 Thread Web Architect
are multiple instances of B associated with an instance of A and > one > > of the instances of B has text='ABCD' (might not be the latest > > date_created), that instance of B is also there in the query result. > > Hmm, I haven't actually tried to run any code, but I'd try reordering >

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-31 Thread Michal Petrucha
created), that instance of B is also there in the query result. Hmm, I haven't actually tried to run any code, but I'd try reordering some of the method calls, and using an explcit field alias for the annotation, which should let you then use an F() expression in subsequent filters; something like

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-31 Thread Web Architect
isn't always 'ABCD' - if there are multiple instances of B associated with an instance of A and one of the instances of B has text='ABCD' (might not be the latest date_created), that instance of B is also there in the query result. Thanks. On Tuesday, August 30, 2016 at 3:59:20 PM UTC+5:30

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Web Architect
Thanks Erik. Will try out the solution you mentioned. On Tuesday, August 30, 2016 at 3:59:20 PM UTC+5:30, Erik Cederstrand wrote: > > > > Den 30. aug. 2016 kl. 11.20 skrev Erik Cederstrand < > erik+...@cederstrand.dk >: > > > > I'm not even sure that's possible to express in SQL, but it would

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Marco Silva
Maybe this can help you https://docs.djangoproject.com/en/1.10/topics/db/aggregation/ terça-feira, 30 de Agosto de 2016 às 07:33:14 UTC+1, Web Architect escreveu: > > Hi, > > I am looking for an elegant and efficient mechanism to have a query filter > or a solution for the follow

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Erik Cederstrand
> Den 30. aug. 2016 kl. 11.20 skrev Erik Cederstrand > : > > I'm not even sure that's possible to express in SQL, but it would probably be > quite convoluted if it is. Here's an easier-to-understand solution: > > res = set() > for b in

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Web Architect
Hi Erik, Thanks for the solution. So, I understand we get all instances of B which are max (date created) or latest (date created) for each instance of A and then we check b.text == 'ABCD' and select the corresponding instance of A. Can't we add additional filter to check if text='ABCD'

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Erik Cederstrand
> for b in B.objects.all().select_related('a').annotate(Max('date_created')): That should probably be: Max('a__b__date_created') instead. Erik -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Erik Cederstrand
if b.text != 'ABCD': continue res.add(a) You'll get too many B objects, but it's only one query. If you want a more optimal query, try to write it in SQL first. Maybe it's possible to express in the ORM. I used set() because 'date_created' is not unique so there could be two B

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Web Architect
UTC+5:30, Mike Dewhirst wrote: > > On 30/08/2016 4:33 PM, Web Architect wrote: > > Hi, > > > > I am looking for an elegant and efficient mechanism to have a query > > filter or a solution for the following one to many relationship model. > > Please note t

Re: A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Mike Dewhirst
On 30/08/2016 4:33 PM, Web Architect wrote: Hi, I am looking for an elegant and efficient mechanism to have a query filter or a solution for the following one to many relationship model. Please note the following is just an illustration of the models - hope it should provide what I am

A tricky query in one to many relationship - atleast for me:)

2016-08-30 Thread Web Architect
Hi, I am looking for an elegant and efficient mechanism to have a query filter or a solution for the following one to many relationship model. Please note the following is just an illustration of the models - hope it should provide what I am looking for: class A(models.Model): name

Re: Django query not returning all objects

2016-08-19 Thread Constantine Covtushenko
cases = HeartFlowCase.objects.values(‘all fields required in your view’). annotate(min_deadline=Min('data__deadline')).order_by('min_deadline') It is the Todor's suggestion extended with value method run. I believe that you need `GROUP BY` in your SQL query and it generated by `values` as said in Django documentation.

Re: Django query not returning all objects

2016-08-19 Thread Simon Charette
d in django doc >> <https://docs.djangoproject.com/en/1.10/ref/models/querysets/#order-by> you >> can use `distinct()` to remove duplicated rows from first query. >> >> I believe with this your pagination should works as expected. >> >> Regard

Re: query values() calls don't use transforms as filter() does

2016-08-19 Thread Rishi Graham
knows how to key into the JSON field. But the second query gives a join error because there is no call to get_transform in Query.add_fields (so "color" is assumed to be a relation). I can get around this with an annotation and some RawSQL, but it's not very clean compar

Re: query values() calls don't use transforms as filter() does

2016-08-18 Thread Tim Graham
I merged support for expressions in values() a few hours ago: https://github.com/django/django/commit/39f35d4b9de223b72c67bb1d12e65669b4e1355b If that doesn't meet your needs, can you give an idea of what the QuerySet you want would look like? On Thursday, August 18, 2016 at 5:10:41 PM UTC-4,

Re: Django query not returning all objects

2016-08-18 Thread Koonal Bharadwaj
Hi Todor, I have implemented something similar: cases = HeartFlowCase.objects.all().annotate(Count('hf_id', distinct=True)) I also tried your suggestion and both seem to produce the same results. The number of duplicates is minimized but not removed entirely. Also the same problem when

Re: Django query not returning all objects

2016-08-18 Thread Koonal Bharadwaj
: > > Hi Koonal, > > As said in django doc > <https://docs.djangoproject.com/en/1.10/ref/models/querysets/#order-by> you > can use `distinct()` to remove duplicated rows from first query. > > I believe with this your pagination should works as expected. > > Regards, &

query values() calls don't use transforms as filter() does

2016-08-18 Thread Rishi Graham
I noticed that the jsonb field indexing in postgres which is so handy in filtering does not seem to extend to calls to values(). After digging around a bit, it seems that sql.query.get_transform() is only called when building a filter, but not when adding fields for a values call. Using

Re: Django query not returning all objects

2016-08-18 Thread Todor Velichkov
: > > Hi Koonal, > > As said in django doc > <https://docs.djangoproject.com/en/1.10/ref/models/querysets/#order-by> you > can use `distinct()` to remove duplicated rows from first query. > > I believe with this your pagination should works as expected. > > Rega

Re: Django query not returning all objects

2016-08-17 Thread Constantine Covtushenko
Hi Koonal, As said in django doc <https://docs.djangoproject.com/en/1.10/ref/models/querysets/#order-by> you can use `distinct()` to remove duplicated rows from first query. I believe with this your pagination should works as expected. Regards, On Thu, Aug 18, 2016 at 2:58 AM,

Django query not returning all objects

2016-08-17 Thread Koonal Bharadwaj
artFlow objects are 5 with 2 CaseDatas each. If I order_by deadline on CaseData as: cases = HeartFlowCase.objects.all().order_by(data__deadline) this returns duplicates since there are multiple CaseDatas, which is fine. Now I try and paginate it by applying: paginator = Paginator(cases, 2) cases = pa

Re: Query annotation with date difference

2016-08-03 Thread Constantine Covtushenko
Sorry, I did not specify. I have been using 'Postgresql' with 'psycopg2 v.2.6.2'. They gave me those results. Also here is a sql query given from log: SELECT "test_app_entity"."id", "test_app_entity"."due_date", "test_app_entity"."interv

Re: Query annotation with date difference

2016-08-03 Thread Yoann Duriaud
Thanks, unfortunately not so great on my side: I added in the query (forgetting the division for now): .annotate(ratio=ExpressionWrapper(F('due_date')-timezone.now(), DateTimeField())) which leads to the following statement in the query: ("contentstatus"."due_date"

Re: Query annotation with date difference

2016-08-02 Thread Constantine Covtushenko
<https://docs.djangoproject.com/en/1.9/ref/models/expressions/#using-f-with-annotations> >>> . >>> Probably the problem is that you use values of different types in your >>> expression. >>> >>> Regards >>> >>> On Sat, Jul 30, 2016 at

Re: Query annotation with date difference

2016-08-01 Thread Constantine Covtushenko
fferent types in your >> expression. >> >> Regards >> >> On Sat, Jul 30, 2016 at 11:35 PM, Yoann Duriaud <yoann@gmail.com> >> wrote: >> >>> Hello, >>> I would like to annotate a query with the following expression: ([Due >

Move python loop to ORM query and fix FieldError in ORM query using Conditional Expressions

2016-08-01 Thread Aditya Saraf
lan_type_and_apn(x_mb)` a couple of times for different values of `x_mb` and wish to create another manager method which helps me run a single query for all the different values of `x_mb`. For this, I have tried creating the following query using [Conditional Expressions](https://docs.djangop

Re: Query annotation with date difference

2016-08-01 Thread Yoann Duriaud
, Jul 30, 2016 at 11:35 PM, Yoann Duriaud <yoann@gmail.com > > wrote: > >> Hello, >> I would like to annotate a query with the following expression: ([Due >> Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the >> database, while [Now] shoul

Re: Query annotation with date difference

2016-07-31 Thread Constantine Covtushenko
n your expression. Regards On Sat, Jul 30, 2016 at 11:35 PM, Yoann Duriaud <yoann.duri...@gmail.com> wrote: > Hello, > I would like to annotate a query with the following expression: ([Due > Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the > data

Query annotation with date difference

2016-07-30 Thread Yoann Duriaud
Hello, I would like to annotate a query with the following expression: ([Due Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the database, while [Now] should be "equal" to timezone.now(). So this would look like: .annotate(ratio=(F('due_date')-timezone.now())/F

Re: Hebrew in Raw Query Like Clause

2016-07-08 Thread Art Zemon
Michal, Actually, your syntax didn't quite work. It threw a couple of warnings and seemed to match all records in the database. But you got me on the right track. This syntax does work properly: select ... where word like concat('%%', %s, '%%') Thanks for getting me pointed in the right

Re: Hebrew in Raw Query Like Clause

2016-07-08 Thread Art Zemon
On Friday, July 8, 2016 at 8:34:00 AM UTC-5, Michal Petrucha wrote: > > I may be wrong, but it seems to me that you're using wrong quoting in > that raw query; I think it should be:: > > select sortkey, book, chapter, verse, hebrew_text > from bible_bible > w

Re: Hebrew in Raw Query Like Clause

2016-07-08 Thread Michal Petrucha
On Thu, Jul 07, 2016 at 11:23:21PM -0500, Art Zemon wrote: > Hello, > > I have a column in a table that contains Hebrew text. I need to do a query > with a LIKE clause on the Hebrew text. The query works if I execute the SQL > directly, either in a SQL window of phpMyAdmin or in

Hebrew in Raw Query Like Clause

2016-07-08 Thread Art Zemon
Hello, I have a column in a table that contains Hebrew text. I need to do a query with a LIKE clause on the Hebrew text. The query works if I execute the SQL directly, either in a SQL window of phpMyAdmin or in a command line mysql client. But I cannot get it to work within Django. I tried

Postgis Raster Query API Spatial Look up. Intersects problem

2016-07-04 Thread Juan Escamilla
. aa = DemMexLow.objects.filter(rast__intersects=t0.biomeGeometry) If I retrieve the data it almost never ends. Takes a lot of time. Examining the raw query I got this: SELECT "demmex120"."rid", "demmex120"."rast" FROM "demmex120"

Re: Date() in Django query

2016-06-15 Thread Simon Charette
for. However, some more complex > queries with the date() function still confuse me. > > For example the SQL query: > > select count(distinct UniqueCallID), date(JoinTime) from Table group by > date(JoinTime); > > > I tried to write it as: > > calls = Call.objects.an

Re: Date() in Django query

2016-06-15 Thread Galil
Thank you Simon, This func expression what was I looking for. However, some more complex queries with the date() function still confuse me. For example the SQL query: select count(distinct UniqueCallID), date(JoinTime) from Table group by date(JoinTime); I tried to write it as: calls

<    2   3   4   5   6   7   8   9   10   11   >