Re: Django ORM generate inefficient SQL

2014-08-28 Thread Alex Lebedev
I have created a ticket - https://code.djangoproject.com/ticket/23383
Should I try to proceed my investigations and create a patch?

пятница, 29 августа 2014 г., 11:50:01 UTC+6 пользователь Simon Charette 
написал:
>
> I think you should create a single issue 
>  pointing to the fact that only 
> selected columns (either through values() or only()) should be grouped by, 
> regardless of the backend.
>
> I suggest you include your initial post body in the report.
>
> Thanks!
>
> Le vendredi 29 août 2014 01:03:03 UTC-4, Alex Lebedev a écrit :
>>
>> Yes, I guess, in this case it should be able to group only by 
>> `auth_group`.`id` for each database backend.
>> Should I create ticket(s) about the issue on MySQL and/or the issue of 
>> columns in "group by" statement, or would you like to do it yourself?
>>
>> четверг, 28 августа 2014 г., 20:36:19 UTC+6 пользователь Simon Charette 
>> написал:
>>>
>>> The issue on MySQL should be tracked in another ticket I guess -- you're 
>>> right that it should be able to GROUP only by `auth_group`.`id`.
>>>
>>> Le jeudi 28 août 2014 07:28:18 UTC-4, Alex Lebedev a écrit :

 Thanks for the answer! Yes, but this problem occurs regardless of 
 database backend (I tested it on PostgreSQL and MySQL)

 среда, 27 августа 2014 г., 12:37:00 UTC+6 пользователь Simon Charette 
 написал:
>
> This is already tracked in #19259 
> .
>
> Le jeudi 21 août 2014 06:49:41 UTC-4, Alex Lebedev a écrit :
>>
>> Hi, guys!
>>
>> I have encountered a problem. When I use the following code in django 
>> shell:
>>
>> from django.contrib.auth.models import Group
>> from django.db.models import Count
>> print Group.objects.annotate(cnt=Count('user')).values('id', 
>> 'cnt').query.sql_with_params()
>>  
>> Django ORM generate the following SQL query:
>>
>> 'SELECT `auth_group`.`id`, COUNT(`auth_user_groups`.`user_id`) AS 
>> `cnt` FROM `auth_group` LEFT OUTER JOIN `auth_user_groups` ON ( 
>> `auth_group`.`id` = `auth_user_groups`.`group_id` ) GROUP BY 
>> `auth_group`.`id`, `auth_group`.`name` ORDER BY NULL'
>>
>> "auth_group.name" occurs in "group by" statement. But this column 
>> isn't represented in "select" statement. Such query is inefficient 
>> (expecially for large tables with many columns and rows).
>>
>> Debuging of Django SQLCompiler ( 
>> https://github.com/django/django/blob/stable/1.6.x/django/db/models/sql/compiler.py#L568
>>  
>> ) gives me the following information:
>> - postgresql:
>> "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
>> u'id'), (u'auth_group', 'name')]"
>> "self.connection.features.allows_group_by_pk" is False
>> "len(self.query.get_meta().concrete_fields) == len(self.query.
>> select)" is False
>> 'auth_group'.'name' appears in result because of "cols = self.
>> query.group_by + having_group_by + select_cols"
>> - mysql:
>> "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
>> u'id'), (u'auth_group', 'name')]"
>> "self.connection.features.allows_group_by_pk" is True
>> "len(self.query.get_meta().concrete_fields) == len(self.query.
>> select)" is False
>> 'auth_group'.'name' appears in result because of "cols = self.
>> query.group_by + having_group_by + select_cols"
>>
>> In the same time, the following code (without .values()):
>>
>> from django.contrib.auth.models import Group
>> from django.db.models import Count
>> print 
>> Group.objects.annotate(cnt=Count('user')).query.sql_with_params()
>>
>> gives the right SQL query for mysql (because "len(self.query.get_meta
>> ().concrete_fields) == len(self.query.select)" is True):
>>
>> 'SELECT `auth_group`.`id`, `auth_group`.`name`, 
>> COUNT(`auth_user_groups`.`user_id`) AS `cnt` FROM `auth_group` LEFT 
>> OUTER 
>> JOIN `auth_user_groups` ON ( `auth_group`.`id` = 
>> `auth_user_groups`.`group_id` ) GROUP BY `auth_group`.`id` ORDER BY NULL'
>>
>> Is it a bug? Should I create a bug report or something?
>>
>> Thanks in advance!
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ffe1264-5170-47b3-b22f-36a27f1ca025%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django ORM generate inefficient SQL

2014-08-28 Thread Simon Charette
I think you should create a single issue 
 pointing to the fact that only 
selected columns (either through values() or only()) should be grouped by, 
regardless of the backend.

I suggest you include your initial post body in the report.

Thanks!

Le vendredi 29 août 2014 01:03:03 UTC-4, Alex Lebedev a écrit :
>
> Yes, I guess, in this case it should be able to group only by 
> `auth_group`.`id` for each database backend.
> Should I create ticket(s) about the issue on MySQL and/or the issue of 
> columns in "group by" statement, or would you like to do it yourself?
>
> четверг, 28 августа 2014 г., 20:36:19 UTC+6 пользователь Simon Charette 
> написал:
>>
>> The issue on MySQL should be tracked in another ticket I guess -- you're 
>> right that it should be able to GROUP only by `auth_group`.`id`.
>>
>> Le jeudi 28 août 2014 07:28:18 UTC-4, Alex Lebedev a écrit :
>>>
>>> Thanks for the answer! Yes, but this problem occurs regardless of 
>>> database backend (I tested it on PostgreSQL and MySQL)
>>>
>>> среда, 27 августа 2014 г., 12:37:00 UTC+6 пользователь Simon Charette 
>>> написал:

 This is already tracked in #19259 
 .

 Le jeudi 21 août 2014 06:49:41 UTC-4, Alex Lebedev a écrit :
>
> Hi, guys!
>
> I have encountered a problem. When I use the following code in django 
> shell:
>
> from django.contrib.auth.models import Group
> from django.db.models import Count
> print Group.objects.annotate(cnt=Count('user')).values('id', 
> 'cnt').query.sql_with_params()
>  
> Django ORM generate the following SQL query:
>
> 'SELECT `auth_group`.`id`, COUNT(`auth_user_groups`.`user_id`) AS 
> `cnt` FROM `auth_group` LEFT OUTER JOIN `auth_user_groups` ON ( 
> `auth_group`.`id` = `auth_user_groups`.`group_id` ) GROUP BY 
> `auth_group`.`id`, `auth_group`.`name` ORDER BY NULL'
>
> "auth_group.name" occurs in "group by" statement. But this column 
> isn't represented in "select" statement. Such query is inefficient 
> (expecially for large tables with many columns and rows).
>
> Debuging of Django SQLCompiler ( 
> https://github.com/django/django/blob/stable/1.6.x/django/db/models/sql/compiler.py#L568
>  
> ) gives me the following information:
> - postgresql:
> "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
> u'id'), (u'auth_group', 'name')]"
> "self.connection.features.allows_group_by_pk" is False
> "len(self.query.get_meta().concrete_fields) == len(self.query.
> select)" is False
> 'auth_group'.'name' appears in result because of "cols = self.
> query.group_by + having_group_by + select_cols"
> - mysql:
> "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
> u'id'), (u'auth_group', 'name')]"
> "self.connection.features.allows_group_by_pk" is True
> "len(self.query.get_meta().concrete_fields) == len(self.query.
> select)" is False
> 'auth_group'.'name' appears in result because of "cols = self.
> query.group_by + having_group_by + select_cols"
>
> In the same time, the following code (without .values()):
>
> from django.contrib.auth.models import Group
> from django.db.models import Count
> print 
> Group.objects.annotate(cnt=Count('user')).query.sql_with_params()
>
> gives the right SQL query for mysql (because "len(self.query.get_meta
> ().concrete_fields) == len(self.query.select)" is True):
>
> 'SELECT `auth_group`.`id`, `auth_group`.`name`, 
> COUNT(`auth_user_groups`.`user_id`) AS `cnt` FROM `auth_group` LEFT OUTER 
> JOIN `auth_user_groups` ON ( `auth_group`.`id` = 
> `auth_user_groups`.`group_id` ) GROUP BY `auth_group`.`id` ORDER BY NULL'
>
> Is it a bug? Should I create a bug report or something?
>
> Thanks in advance!
>


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/382c79a8-6e76-4f82-9f80-0730b79c60f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django admin can't display user detail view: 500 error

2014-08-28 Thread Babatunde Akinyanmi
Hi Amarshall?
We need more information. Give us the traceback
On 29 Aug 2014 01:22, "amarshall"  wrote:

> I've deployed my django application using Nginx and uWSGI.
>
> In development I can login to my django admin-> users-> [username] and it
> shows the users information. However in development once I click on a user
> I get a "server 500" error. I have the same code for both deployment and
> development. I can't think of what the problem could be ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/176e31ad-5b35-429b-ad61-33753bcd30c4%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BWjgXMiTAyRBgs2Z%2BO4fP7u3sionYYnDvGpOXN3%3DHiSu-eY9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Djamgo wizard problem

2014-08-28 Thread Babatunde Akinyanmi
Hi Mihai,
Ee can't help you without enough information. You need to at least give the
traceback of the error
On 28 Aug 2014 21:28, "Mihai Andrei Gabara" 
wrote:

> Hi! who can help me with "wizard" problem. i have 7 steps. every step have
> the "next" and "back" buttons. the back button works up to the 4 step, in
> the next steps, it return me an error. when i finish the steps, it starts a
> new wizard but i need to change page.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c8e7c239-9d49-49ea-ba92-ec7fa36987f8%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BWjgXOrYiKO7b%3DXKBnqJdi8Mup6Q5kRhayqkk03qYw%3DTXG0Ew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django ORM generate inefficient SQL

2014-08-28 Thread Alex Lebedev
Yes, I guess, in this case it should be able to group only by 
`auth_group`.`id` for each database backend.
Should I create ticket(s) about the issue on MySQL and/or the issue of 
columns in "group by" statement, or would you like to do it yourself?

четверг, 28 августа 2014 г., 20:36:19 UTC+6 пользователь Simon Charette 
написал:
>
> The issue on MySQL should be tracked in another ticket I guess -- you're 
> right that it should be able to GROUP only by `auth_group`.`id`.
>
> Le jeudi 28 août 2014 07:28:18 UTC-4, Alex Lebedev a écrit :
>>
>> Thanks for the answer! Yes, but this problem occurs regardless of 
>> database backend (I tested it on PostgreSQL and MySQL)
>>
>> среда, 27 августа 2014 г., 12:37:00 UTC+6 пользователь Simon Charette 
>> написал:
>>>
>>> This is already tracked in #19259 
>>> .
>>>
>>> Le jeudi 21 août 2014 06:49:41 UTC-4, Alex Lebedev a écrit :

 Hi, guys!

 I have encountered a problem. When I use the following code in django 
 shell:

 from django.contrib.auth.models import Group
 from django.db.models import Count
 print Group.objects.annotate(cnt=Count('user')).values('id', 
 'cnt').query.sql_with_params()
  
 Django ORM generate the following SQL query:

 'SELECT `auth_group`.`id`, COUNT(`auth_user_groups`.`user_id`) AS 
 `cnt` FROM `auth_group` LEFT OUTER JOIN `auth_user_groups` ON ( 
 `auth_group`.`id` = `auth_user_groups`.`group_id` ) GROUP BY 
 `auth_group`.`id`, `auth_group`.`name` ORDER BY NULL'

 "auth_group.name" occurs in "group by" statement. But this column 
 isn't represented in "select" statement. Such query is inefficient 
 (expecially for large tables with many columns and rows).

 Debuging of Django SQLCompiler ( 
 https://github.com/django/django/blob/stable/1.6.x/django/db/models/sql/compiler.py#L568
  
 ) gives me the following information:
 - postgresql:
 "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
 u'id'), (u'auth_group', 'name')]"
 "self.connection.features.allows_group_by_pk" is False
 "len(self.query.get_meta().concrete_fields) == len(self.query.
 select)" is False
 'auth_group'.'name' appears in result because of "cols = self.query
 .group_by + having_group_by + select_cols"
 - mysql:
 "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
 u'id'), (u'auth_group', 'name')]"
 "self.connection.features.allows_group_by_pk" is True
 "len(self.query.get_meta().concrete_fields) == len(self.query.
 select)" is False
 'auth_group'.'name' appears in result because of "cols = self.query
 .group_by + having_group_by + select_cols"

 In the same time, the following code (without .values()):

 from django.contrib.auth.models import Group
 from django.db.models import Count
 print 
 Group.objects.annotate(cnt=Count('user')).query.sql_with_params()

 gives the right SQL query for mysql (because "len(self.query.get_meta()
 .concrete_fields) == len(self.query.select)" is True):

 'SELECT `auth_group`.`id`, `auth_group`.`name`, 
 COUNT(`auth_user_groups`.`user_id`) AS `cnt` FROM `auth_group` LEFT OUTER 
 JOIN `auth_user_groups` ON ( `auth_group`.`id` = 
 `auth_user_groups`.`group_id` ) GROUP BY `auth_group`.`id` ORDER BY NULL'

 Is it a bug? Should I create a bug report or something?

 Thanks in advance!

>>>

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


Re: Widget for simple (not input) text

2014-08-28 Thread Yarick Antonov
Yes. Many thanks :)

On Friday, August 29, 2014 6:14:10 AM UTC+4, Matt Gushee wrote:
>
> What do you want to do with this 'widget'? From your description, it 
> sounds like you could use a normal paragraph element -- which might 
> look something like this in a Django template: 
>
>{{ some_text }} 
>
> Does that not meet your needs? 
>
> -- 
> Matt Gushee 
>
> On Thu, Aug 28, 2014 at 5:51 PM, Yarick Antonov  > wrote: 
> > Does Django (or HTML itself) contain any sort of TextField, what 
> represent 
> > not the form for text input but simple, static not editable text? 
> > I mean something like this: http://i.imgur.com/Nv0XN0J.png 
> > 
> > Is it possible to have a widget for that data, or i can use simple 
> string to 
> > do this? 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to django-users...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at http://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/92f5c4d1-4d10-41cb-b34d-d9701a394493%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

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


Re: Widget for simple (not input) text

2014-08-28 Thread Matt Gushee
What do you want to do with this 'widget'? From your description, it
sounds like you could use a normal paragraph element -- which might
look something like this in a Django template:

   {{ some_text }}

Does that not meet your needs?

--
Matt Gushee

On Thu, Aug 28, 2014 at 5:51 PM, Yarick Antonov  wrote:
> Does Django (or HTML itself) contain any sort of TextField, what represent
> not the form for text input but simple, static not editable text?
> I mean something like this: http://i.imgur.com/Nv0XN0J.png
>
> Is it possible to have a widget for that data, or i can use simple string to
> do this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/92f5c4d1-4d10-41cb-b34d-d9701a394493%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABrD0ee6imW-KAJ1kwQeKagSV_-MqPJJ4_ZoB48jF7BkK%2BbcAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I create models which only required during tests in Django 1.7c1?

2014-08-28 Thread Yo-Yo Ma
Ugh... same problem here. It seems you can't really create a model in setUp 
anymore. I'll post a reply, if I find anything.

On Wednesday, July 16, 2014 10:17:56 AM UTC-4, Alisue Lambda wrote:
>
> Hi all. 
>
> Well today I tried Django 1.7c1 with my program and found that the 
> previous testing strategy seems not work.
>
> I have several models which only required during tests. Before Django 1.7, 
> I could create these kind of temporary models by defining these in 
> `app/tests/models.py` with `app_label` specification like this (
> https://github.com/lambdalisue/django-permission/blob/master/src/permission/tests/models.py).
>  
> It was quite good strategy for me because I could reduce the dependency of 
> the apps and make the app independent.
>
> But now, it seems Django 1.7c1 cannot find this kind of definitions. I 
> have to add `app.tests` in `INSTALLED_APPS` which was not required before 
> Django 1.7c1.
> However, if I add `app.tests` and `app2.tests`, I have to modify `label` 
> of the `app2.tests` because there is already `app_label='tests'` in the 
> registry. It is quite tough job while I have a lot of apps which follow 
> this strategy to test the app.
> Additionally, I don't really want to list `app.tests` in my 
> `INSTALLED_APPS` while it is not actually app which required for the site.
>
> So I wonder if there are any better way to define the temporary models. In 
> summary, what I want to do is
>
> 1. I want to add temporary models which only required during tests
> 2. I don't want to mess the db with temporary models (except during tests)
>
> Any idea? Thank you for your cooperation.
>
>
> Best regard,
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2a208687-4cf9-461f-9347-3a7efbfa066c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django admin can't display user detail view: 500 error

2014-08-28 Thread amarshall
I've deployed my django application using Nginx and uWSGI. 

In development I can login to my django admin-> users-> [username] and it 
shows the users information. However in development once I click on a user 
I get a "server 500" error. I have the same code for both deployment and 
development. I can't think of what the problem could be ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/176e31ad-5b35-429b-ad61-33753bcd30c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Widget for simple (not input) text

2014-08-28 Thread Yarick Antonov
Does Django (or HTML itself) contain any sort of TextField, what represent 
not the form for text input but simple, static not editable text?
I mean something like this: http://i.imgur.com/Nv0XN0J.png

Is it possible to have a widget for that data, or i can use simple string 
to do this?

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


Djamgo wizard problem

2014-08-28 Thread Mihai Andrei Gabara
Hi! who can help me with "wizard" problem. i have 7 steps. every step have 
the "next" and "back" buttons. the back button works up to the 4 step, in 
the next steps, it return me an error. when i finish the steps, it starts a 
new wizard but i need to change page.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c8e7c239-9d49-49ea-ba92-ec7fa36987f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Constants values and best practices

2014-08-28 Thread Andrew Pinkham
Hi Julian,

I think there are a couple options.

The easiest would be to store the constants as Python. I would recommend using 
the choices field, as detailed by the documentation:

https://docs.djangoproject.com/en/1.7/ref/models/fields/#choices

If you must store your constants as part of the database, and would like to 
keep the constants up to date across multiple databases/developers, you should 
look into data migrations. South provides them, as do the new migrations in 
Django 1.7 (I believe).

http://south.readthedocs.org/en/latest/tutorial/part3.html

Hope that helps,
Andrew

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7E584188-D6CB-46C9-ABC1-C0E64B2D23FA%40andrewsforge.com.
For more options, visit https://groups.google.com/d/optout.


Re: Constants values and best practices

2014-08-28 Thread yati sagade
Hi Julian

Python 3 introduces enums, which should make this easy:
https://docs.python.org/3/library/enum.html
In my Python 2 projects, I define a class to club together related
constants. Something like,

class PurchaseState(object):
EGGS = 'eggs'
FOO = 'foo'
BAR = 'bar'

and then do

if  purchase.state == PurchaseState.EGGS:
# do stuff

Note that I prefer using string values for my constants over integer
values, as it makes debugging far more pleasant.

Cheers

On Thu, Aug 28, 2014 at 10:33 PM, Julo Waks  wrote:
> Good day!
> How are you?
> I have the following situation:
>
> In more than one django project I come across the situation where I need to
> define a model that has a State.
> So what I usually do is:
>
> # Pseudo code here
>
> def State (models.Model):
>  name = models.CharField ()
>
> def Purchase (models.Model):
>  # Fields various (name, descrption, etc)
>  State = models.ForgeinKey (State)
>  # More fields ...
>
> The problem arises when I want to do things like:
>
> if (Purchase.State_id == 1):
>
> # Do stuff
>
>
> my way to fix it so far was to define a const.py and do something like:
>
> if (== Purchase.State_id Const.STATE_EGGS):
>
> # Do stuff
>
> Because the state 1 is "eggs", but because I add in my local, but if another
> dev adds in staging, as that uniformity is maintained?
> It should create a process that creates the updates as new constants was
> defined?
> There are best practices for this?
>
> Ideas? Advice?
>
> Thank you very much for reading =)
>
> regards,
> Julian.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAKSEZ1EfdSiaNwd6ZxL0NUhfn3HM39zdbg1CVkRXNyObwLxjcA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Yati Sagade

Software Engineer at mquotient

Twitter: @yati_itay | Github: yati-sagade

Organizing member of TEDx EasternMetropolitanBypass
http://www.ted.com/tedx/events/4933
https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANpY%2BHkT%2BwPAT6gh%2BDoDQ418x83BYvnV%2BQs3goY23LYCcSX5yw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Constants values and best practices

2014-08-28 Thread Julo Waks
Good day!
How are you?
I have the following situation:

In more than one django project I come across the situation where I need to
define a model that has a State.
So what I usually do is:

# Pseudo code here

def State (models.Model):
 name = models.CharField ()

def Purchase (models.Model):
 # Fields various (name, descrption, etc)
 State = models.ForgeinKey (State)
 # More fields ...

The problem arises when I want to do things like:

if (Purchase.State_id == 1):

# Do stuff


my way to fix it so far was to define a const.py and do something like:

if (== Purchase.State_id Const.STATE_EGGS):

# Do stuff

Because the state 1 is "eggs", but because I add in my local, but if
another dev adds in staging, as that uniformity is maintained?
It should create a process that creates the updates as new constants was
defined?
There are best practices for this?

Ideas? Advice?

Thank you very much for reading =)

regards,
Julian.

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


Re: New user - struggling with database design

2014-08-28 Thread Jason G
Ok - here is where I am stuck now. Any thoughts?

If I try to render {{ vessel.CurrentBrew }} in a view, I get something like 
this:


and this errors out:

{% for Brew in vessel.CurrentBrew.all %}X{{ Brew.ActualName }}{% 
endfor %}

(1146, "Table 'dbLunawireBrewing.brewlog_vessel_CurrentBrew' doesn't exist")



The vessel model looks like this:

class Vessel(models.Model):
Name = models.CharField(max_length=20)
ShortName = models.CharField(max_length=4)
Gallons = models.DecimalField(max_digits=4, decimal_places=2, null=True, 
blank=True)
Weight = models.DecimalField(max_digits=4, decimal_places=2, null=True, 
blank=True)
CurrentBrew  = models.ManyToManyField('Brew', related_name="brew")
def __unicode__(self):
return self.Name


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2363ed3e-a787-46a0-b887-7706d0a9c315%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.7 not working with mysql-connector-python 1.1.6 & Python 3.3 ?

2014-08-28 Thread cico
And I wish I could upvote your solution to heaven!
Thanks for sharing that, why is it not documented anywhere? Sounds like a 
killing feature..

Cheers!
mccc

On Saturday, May 10, 2014 1:00:12 AM UTC+2, Richard Esplin wrote:
>
> Thanks for sharing what you did. I wish PostgreSQL was an option for me on 
> this project. 
>
> Oracle's answer was pretty generic, but they are right that Django 1.7 is 
> still in development. It is good to know that they are planning to support 
> it 
> when it is released. I am glad I don't have to roll-out 1.6 and then 
> manage an 
> upgrade a few months after our launch. 
>
> PyMySQL appears to work fine, but I haven't benchmarked it yet. Knowing 
> that I 
> can drop in the Oracle connector if there is a problem makes me confident 
> to 
> move forward. 
>
> Cheers, 
>
> Richard 
>
> On Friday, May 09, 2014 14:49:11 Giovanni wrote: 
> > I switched to PostgreSQL when MySQL wasn't working. PostgreSQL worked 
> > without a hitch and the migrations work wonderfully. But since my target 
> > production environment only runs MySQL I will have to make the switch 
> back 
> > at some point. 
> > 
> > Thanks for submitting the bug to MySQL. I see they posted a somewhat 
> > generic answer. 
> > 
> > On Tuesday, May 6, 2014 11:52:07 AM UTC-4, Richard Esplin wrote: 
> > > In order to move forward with this project, I switched to PyMySQL: 
> > > 
> > > https://github.com/PyMySQL 
> > > 
> > > It appears to work great. In order to use the default Django backend 
> for 
> > > MySQL, I put this in my settings.py: 
> > > 
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0c46dae7-98a1-4758-8869-a1faccad04e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Unhandled Exception on first time deployment (works on home PC)

2014-08-28 Thread Tarik Hamilton
Hi, I'm new to Django. I been having a lot of fun developing it on my home 
computer, but I wanted to access it everywhere finally.

I followed* this 
*guide
 
from my host, involving virtualenv and fastcgi. Python and Django were 
successfully installed and I can run Python commands and reference Django 
objects in SSH, but ...

I get Unhandled Exception is absolutely everywhere on my site, so something 
is wrong in the setup. Django is for sure installed.

Since deploying Django onto my site, the only difference from my 
development environment is:
- Django project name is different
- settings.py - ROOT_URLCONF and WSGI_APPLICATION updated to new project 
name
- settings.py - added my sites to ALLOWED_HOSTS (a solution attempt)
- settings.py - I turned debug mode off (as well as back on)
- settings.py - Added my only app to the list (also removed)

The only difference I can confirm for sure is that it is 1.6.6 vs 1.6.5 on 
my computer.

Tech support replied with this: 

*(env) m...@me.com [~]# pip list | grep flashcards*
*flashcards (2.4)*

*What's interesting is the error now reports the following:*

*OSError: [Errno 2] No such file or directory: '/root/Documents/flashcards'*
*Content-Type: text/html*

*This seems to be some kind of configuration / script issue - please ask 
your web developer to review the above - it should reference your home 
directory (/home/tarikham).*


I am inexperienced, but I can say for certain there is no reference to 
"Documents" in my app or Django project. I made a program with knowledge 
gained from the main Django tutorial.

I don't know where else to look or how to troubleshoot. Django has been so 
straightforward. There's settings.py, .htaccess, and the fcgi file. I'm 
going to post the .htaccess and fcgi. 

The only thing I can say that's weird about the .htaccess and dipsatch.fcgi 
is that they are placed in my /public_html/ folder, where as my Django code 
is in the root, which I heard you're supposed to do. I don't know what 
makes the "connection."

# Replaced my home folder (?) with "me"
# This is dispatch.fcgi

#!/home/me/.env/env/bin/python

import sys
import os

sys.path.insert(0, '/home/me/.env/env/lib/python2.6/site-packages')

os.environ['DJANGO_SETTINGS_MODULE'] = 'tarikhamilton.settings'

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]

Thanks for reading this.

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


Re: Django ORM generate inefficient SQL

2014-08-28 Thread Simon Charette
The issue on MySQL should be tracked in another ticket I guess -- you're 
right that it should be able to GROUP only by `auth_group`.`id`.

Le jeudi 28 août 2014 07:28:18 UTC-4, Alex Lebedev a écrit :
>
> Thanks for the answer! Yes, but this problem occurs regardless of 
> database backend (I tested it on PostgreSQL and MySQL)
>
> среда, 27 августа 2014 г., 12:37:00 UTC+6 пользователь Simon Charette 
> написал:
>>
>> This is already tracked in #19259 
>> .
>>
>> Le jeudi 21 août 2014 06:49:41 UTC-4, Alex Lebedev a écrit :
>>>
>>> Hi, guys!
>>>
>>> I have encountered a problem. When I use the following code in django 
>>> shell:
>>>
>>> from django.contrib.auth.models import Group
>>> from django.db.models import Count
>>> print Group.objects.annotate(cnt=Count('user')).values('id', 
>>> 'cnt').query.sql_with_params()
>>>  
>>> Django ORM generate the following SQL query:
>>>
>>> 'SELECT `auth_group`.`id`, COUNT(`auth_user_groups`.`user_id`) AS 
>>> `cnt` FROM `auth_group` LEFT OUTER JOIN `auth_user_groups` ON ( 
>>> `auth_group`.`id` = `auth_user_groups`.`group_id` ) GROUP BY 
>>> `auth_group`.`id`, `auth_group`.`name` ORDER BY NULL'
>>>
>>> "auth_group.name" occurs in "group by" statement. But this column isn't 
>>> represented in "select" statement. Such query is inefficient 
>>> (expecially for large tables with many columns and rows).
>>>
>>> Debuging of Django SQLCompiler ( 
>>> https://github.com/django/django/blob/stable/1.6.x/django/db/models/sql/compiler.py#L568
>>>  
>>> ) gives me the following information:
>>> - postgresql:
>>> "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
>>> u'id'), (u'auth_group', 'name')]"
>>> "self.connection.features.allows_group_by_pk" is False
>>> "len(self.query.get_meta().concrete_fields) == len(self.query.select
>>> )" is False
>>> 'auth_group'.'name' appears in result because of "cols = self.query.
>>> group_by + having_group_by + select_cols"
>>> - mysql:
>>> "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
>>> u'id'), (u'auth_group', 'name')]"
>>> "self.connection.features.allows_group_by_pk" is True
>>> "len(self.query.get_meta().concrete_fields) == len(self.query.select
>>> )" is False
>>> 'auth_group'.'name' appears in result because of "cols = self.query.
>>> group_by + having_group_by + select_cols"
>>>
>>> In the same time, the following code (without .values()):
>>>
>>> from django.contrib.auth.models import Group
>>> from django.db.models import Count
>>> print 
>>> Group.objects.annotate(cnt=Count('user')).query.sql_with_params()
>>>
>>> gives the right SQL query for mysql (because "len(self.query.get_meta().
>>> concrete_fields) == len(self.query.select)" is True):
>>>
>>> 'SELECT `auth_group`.`id`, `auth_group`.`name`, 
>>> COUNT(`auth_user_groups`.`user_id`) AS `cnt` FROM `auth_group` LEFT OUTER 
>>> JOIN `auth_user_groups` ON ( `auth_group`.`id` = 
>>> `auth_user_groups`.`group_id` ) GROUP BY `auth_group`.`id` ORDER BY NULL'
>>>
>>> Is it a bug? Should I create a bug report or something?
>>>
>>> Thanks in advance!
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8711e8b3-f869-4ab7-8166-4618bd173da0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: HttpResponse methods difference

2014-08-28 Thread Collin Anderson
It's the same as python file objects
write sends data to the response
flush makes sure the data you wrote is actually getting sent out, not just 
buffered for alter
tell tells you how much data you've read or written. is where are you in 
the "file"
https://docs.python.org/3/library/io.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6e86f103-30e6-4b86-bcde-f5c432899410%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: HttpResponse methods difference

2014-08-28 Thread marc
As you see in: 
https://github.com/django/django/blob/master/django/http/response.py#L370 
all three methods have different usecases.

.write(string) <- adds content
.tell() <- returns the length of content
.flush() <- just passing, does nothing (since at lease v1.5)

Cheers

Am Donnerstag, 28. August 2014 02:48:16 UTC+2 schrieb Yarick Antonov:
>
> What the difference between HttpResponse.Write() 
> ,
>  
> HttpResponse.flush() 
> 
>  
> and HttpResponse.tell() 
> 
>  
> methods?
>
> 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/961ac065-bb0e-408f-82be-9e1f05ce76a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New user - struggling with database design

2014-08-28 Thread Jason G
Hi Gerald - thanks for the quick reply! Turns out it was just an issue with 
quotes...not sure I am doing it right just yet, but at least I've passed 
the error.

>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7b725cda-6078-4859-8e20-4ef05d2d2c8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New user - struggling with database design

2014-08-28 Thread Gerald Klein
their order if I am understanding you right does not effect this, the last
part is just  a join between the tables, you don't have to create another
table


On Thu, Aug 28, 2014 at 8:46 AM, Jason G  wrote:

> Hi all,
>
> I am building an app to track my home brewing.
>
> I have two tables, one for vessels, and another for brews.
>
> I want the Brew table to have a pick-list, relation to Vessels so I can
> say what vessel the brew is in.
>
> I also want to render a table that shows all Vessels and what Brew is in
> each. There should be a one-to-one relationship until the Brew is 'Kicked',
> which could be a vessel or maybe a null value in the Brew table.
>
> My code currently doesn't work, but looks something like this:
>
> class Vessel(models.Model):
> Name = models.CharField(max_length=20)
> Gallons = models.DecimalField(max_digits=4, decimal_places=2,
> null=True, blank=True)
> Weight = models.DecimalField(max_digits=4, decimal_places=2,
> null=True, blank=True)
> CurrentBrew  = models.ForeignKey(Brew, db_column='Vessel')
>  <--this is what I'm trying to add
> def __unicode__(self):
> return self.Name
>
> class Brew(models.Model):
> ...
> Name = models.CharField(max_length=40, null=True, default='TBD')
> InformalName = models.CharField(max_length=40)
> Status = models.IntegerField(max_length=1, choices=STATUS_CHOICES,
> default=1, null=False, blank=False)
> Gallons = models.DecimalField(max_digits=4, decimal_places=2,
> null=True, blank=True)
> Vessel = models.ForeignKey(Vessel)
> Style = models.ForeignKey(Style)
> Event = models.CharField(max_length=40, null=True, blank=True)
>
> In this model, which I'm not sure is the best way to do it, the Vessel
> class does not yet know about the Brew model that is below it.
>
> I'm starting to grasp this language (and love it, coming from doing
> asp/sql several years ago) but I'm stuck here. Help!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/dd40f53a-c398-4806-b09d-1605d3f15ead%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Gerald Klein DBA

contac...@geraldklein.com

www.geraldklein.com 

geraldklein.wordpress.com

j...@zognet.com

708-599-0352


Arch, Gentoo I3, Ranger & Vim the coding triple threat.

Linux registered user #548580

Brought to you by the Amish Mafia

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAP8NtCz9%2BURQG23wR%3DXSkUozJ7vFvDXOnp5cfyRPMFdXTOJ%2BzQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


New user - struggling with database design

2014-08-28 Thread Jason G
Hi all,

I am building an app to track my home brewing.

I have two tables, one for vessels, and another for brews.

I want the Brew table to have a pick-list, relation to Vessels so I can say 
what vessel the brew is in.

I also want to render a table that shows all Vessels and what Brew is in 
each. There should be a one-to-one relationship until the Brew is 'Kicked', 
which could be a vessel or maybe a null value in the Brew table.

My code currently doesn't work, but looks something like this:

class Vessel(models.Model):
Name = models.CharField(max_length=20)
Gallons = models.DecimalField(max_digits=4, decimal_places=2, 
null=True, blank=True)
Weight = models.DecimalField(max_digits=4, decimal_places=2, null=True, 
blank=True)
CurrentBrew  = models.ForeignKey(Brew, db_column='Vessel') 
 <--this is what I'm trying to add
def __unicode__(self):
return self.Name

class Brew(models.Model):
...
Name = models.CharField(max_length=40, null=True, default='TBD')
InformalName = models.CharField(max_length=40)
Status = models.IntegerField(max_length=1, choices=STATUS_CHOICES, 
default=1, null=False, blank=False)
Gallons = models.DecimalField(max_digits=4, decimal_places=2, 
null=True, blank=True)
Vessel = models.ForeignKey(Vessel)
Style = models.ForeignKey(Style)
Event = models.CharField(max_length=40, null=True, blank=True)

In this model, which I'm not sure is the best way to do it, the Vessel 
class does not yet know about the Brew model that is below it.

I'm starting to grasp this language (and love it, coming from doing asp/sql 
several years ago) but I'm stuck here. Help!

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


Re: Django ORM generate inefficient SQL

2014-08-28 Thread Alex Lebedev
Thanks for the answer! Yes, but this problem occurs regardless of database 
backend (I tested it on PostgreSQL and MySQL)

среда, 27 августа 2014 г., 12:37:00 UTC+6 пользователь Simon Charette 
написал:
>
> This is already tracked in #19259 
> .
>
> Le jeudi 21 août 2014 06:49:41 UTC-4, Alex Lebedev a écrit :
>>
>> Hi, guys!
>>
>> I have encountered a problem. When I use the following code in django 
>> shell:
>>
>> from django.contrib.auth.models import Group
>> from django.db.models import Count
>> print Group.objects.annotate(cnt=Count('user')).values('id', 
>> 'cnt').query.sql_with_params()
>>  
>> Django ORM generate the following SQL query:
>>
>> 'SELECT `auth_group`.`id`, COUNT(`auth_user_groups`.`user_id`) AS 
>> `cnt` FROM `auth_group` LEFT OUTER JOIN `auth_user_groups` ON ( 
>> `auth_group`.`id` = `auth_user_groups`.`group_id` ) GROUP BY 
>> `auth_group`.`id`, `auth_group`.`name` ORDER BY NULL'
>>
>> "auth_group.name" occurs in "group by" statement. But this column isn't 
>> represented in "select" statement. Such query is inefficient (expecially 
>> for large tables with many columns and rows).
>>
>> Debuging of Django SQLCompiler ( 
>> https://github.com/django/django/blob/stable/1.6.x/django/db/models/sql/compiler.py#L568
>>  
>> ) gives me the following information:
>> - postgresql:
>> "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
>> u'id'), (u'auth_group', 'name')]"
>> "self.connection.features.allows_group_by_pk" is False
>> "len(self.query.get_meta().concrete_fields) == len(self.query.select)" 
>> is False
>> 'auth_group'.'name' appears in result because of "cols = self.query.
>> group_by + having_group_by + select_cols"
>> - mysql:
>> "self.query.select" == "self.query.group_by" == "[(u'auth_group', 
>> u'id'), (u'auth_group', 'name')]"
>> "self.connection.features.allows_group_by_pk" is True
>> "len(self.query.get_meta().concrete_fields) == len(self.query.select)" 
>> is False
>> 'auth_group'.'name' appears in result because of "cols = self.query.
>> group_by + having_group_by + select_cols"
>>
>> In the same time, the following code (without .values()):
>>
>> from django.contrib.auth.models import Group
>> from django.db.models import Count
>> print 
>> Group.objects.annotate(cnt=Count('user')).query.sql_with_params()
>>
>> gives the right SQL query for mysql (because "len(self.query.get_meta().
>> concrete_fields) == len(self.query.select)" is True):
>>
>> 'SELECT `auth_group`.`id`, `auth_group`.`name`, 
>> COUNT(`auth_user_groups`.`user_id`) AS `cnt` FROM `auth_group` LEFT OUTER 
>> JOIN `auth_user_groups` ON ( `auth_group`.`id` = 
>> `auth_user_groups`.`group_id` ) GROUP BY `auth_group`.`id` ORDER BY NULL'
>>
>> Is it a bug? Should I create a bug report or something?
>>
>> Thanks in advance!
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4222-09dd-4c89-98d7-6b01b8636713%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django manage.py commands not displaying

2014-08-28 Thread RSS
Thank you, Very much!
Yes, that's an ancient manage.py

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f9e745c-5e7c-4f3f-b7de-4a4fff840a83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: response to ajax (jquery) with variables

2014-08-28 Thread Andreas Kuhne
Hi Antonio,

import simplejson as json

return HttpResponse(
json.dumps({
'array': example
}),
content_type="application/json"
)

That would do the trick. This is returned as JSON. Remember to set the
content_type, otherwise the client can get confused.

Regards,

Andréas

2014-08-28 2:56 GMT+02:00 Antonio Russoniello :

>  Hello,
>
> i hope you can help me with this, I'm trying to send to an ajax (jquery
> from my html template) a response but i would like to send also a new
> variable.
>
> in my html template I have:
>
> $("#init_date").click(function(){
> var some_date = {'init_date': init_date, 'end_date': end_date};
> $.post("/filter_dates/", some_date, function(response){
> if(response === 'success'){
> *MAKE SOMETHING**!!!*
> else{ alert('error'); }
> });
> });
>
> my django view look like:
>
> def filter_date(request):
> if request.method == 'POST':
> example = ['A','B','C']
> init_date = request.POST['init_date']
> end_date = request.POST['end_date']
>  MAKE SOMETHING!!
> return HttpResponse('success') *AND HERE I WOULD LIKE TO SEND THE
> example ARRAY...*
> else:
> return HttpResponse('error')
>
> How can I send the array o some other variable as response?
>
> Regards,
> AR
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/53FE7E44.4020104%40musicparticles.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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