Re: how to call django web page with ordinary html page

2014-08-29 Thread Pawan Soni


On Friday, August 29, 2014 5:47:19 PM UTC+5:30, Shubham Pansari wrote:
>
> You are missing csrf_token which is set by request for csrf verification. 
> After the line 
> http://127.0.0.1:8000/test/; method="post">
> in your code put {%csrf_token%} and it should work fine and also read why 
> it didnot worked without it from 
> https://docs.djangoproject.com/en/dev/ref/contrib/csrf/  . This should 
> answer all your queries.
>
>
> On Fri, Aug 29, 2014 at 4:36 PM, Pawan Soni  > wrote:
>
>> Hi ,
>>
>> i have a simple html page,*p.html *which is not made in django 
>> application ,its just a ordinary html page  which look like..
>>
>> 
>> 
>> http://127.0.0.1:8000/test/; method="post">
>> 
>> 
>> 
>> 
>>
>> In form's action i am passing the path of my django url..
>>
>> this is my *urls.py* file..
>>
>>  from django.conf.urls import patterns, include, url
>> from django.contrib import admin
>> from login import views
>>   urlpatterns = patterns('',
>>url(r'^test',views.paymentcheck_view,name="test"),
>>)
>>
>> my *views.py.*.
>> 
>>  def paymentcheck_view(request):
>>if request.method == "POST":
>> c = {}
>> c.update(csrf(request))
>> return render_to_response('login1/create_pay_page.html',c)
>>else:
>> return HttpResponse('GET')
>>
>> Error i got ...
>>
>> Forbidden (403)
>>
>> CSRF verification failed. Request aborted.
>> 
>> 
>> i am stuck over here,pls help me 
>>
>> Thnx in advance
>>
>>
>> 
>>
>  Thanks Shubham for guiding me and your precious response,but 
my concern is that if i used simple/plain html page and if i would use 
{%csrf_token %} in that page ,i think this is not working .
  Is any other alternative ways to do this task.
Thanks :)


  

>  -- 
>> 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/2b21261b-c48f-43d2-8db0-810b0c7a9c02%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/ed8d597a-5897-4be2-9402-f77d464700ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: related_query_name - what is it?

2014-08-29 Thread Petr Glotov
No problem.

I think I also found how to deal with M instances which are not related to 
R (R instances have foreign key to M). I tried 
M.filter(related_query_name_from_R__isnull=False) and it seems to work.

-- 
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/7881889c-c9df-4793-bfcb-7b488fbca7fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: related_query_name - what is it?

2014-08-29 Thread Simon Charette
The documentation is wrong, it should be:

# That's now the name of the reverse filter
Article.objects.*filter*(tag__name="important")

I'll commit a documentation admonition and give you credit.

Thanks for spotting this!

Le vendredi 29 août 2014 22:27:38 UTC-4, Petr Glotov a écrit :
>
> Correction: first sentence of the question should read:
> However, a model instance doesn't have filter() method. 
>

-- 
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/8ec56a2f-2619-4683-b506-45f62b8d7ad1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: response to ajax (jquery) with variables

2014-08-29 Thread Antonio Russoniello
Now I can read data from  ajax to my def but I have not idea to how 
send, for examle, an array to jquery and manage this from javascript...


I tried:

def json_prueba(request):
arrg = [1,2,3,4]
if request.method == 'POST':
return HttpResponse(simplejson.dumps({'array': arrg}), 
content_type="application/json")

return HttpResponse('FAIL!')

from the page side:

function updateDB(){
$.post("/sitioweb/json/", data, function(response){
if(response){
var data = JSON.parse(*response*); <- NOT SURE 
IF THIS IS CORRECT
alert(data[0]); }  <- I´m trying to put 
on an alert windows the first item of my array arrg

else{ alert('Error! :(');}
});
}

Thanks in advande.
AR


El 28/08/2014 02:57 a.m., Andreas Kuhne escribió:

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.


--
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/54013DA3.3090901%40musicparticles.com.
For more options, visit https://groups.google.com/d/optout.


Re: related_query_name - what is it?

2014-08-29 Thread Petr Glotov
Correction: first sentence of the question should read:
However, a model instance doesn't have filter() method. 

-- 
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/25528fa6-8d01-44a3-b8f7-1230f68f96d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: response to ajax (jquery) with variables

2014-08-29 Thread Antonio Russoniello

Thanks Andréas,

I will try it.

Regards/AR


El 28/08/2014 02:57 a.m., Andreas Kuhne escribió:

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.


--
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/540136FE.9000809%40musicparticles.com.
For more options, visit https://groups.google.com/d/optout.


related_query_name - what is it?

2014-08-29 Thread Petr Glotov
Django doc says:

 ForeignKey.related_query_name
New in Django 1.6.
The name to use for the reverse filter name from the target model. Defaults 
to the value of related_name if it is set, otherwise it defaults to the 
name of the model:

# Declare the ForeignKey with related_query_name
class Tag(models.Model):
article = models.ForeignKey(Article, related_name="tags", 
related_query_name="tag")
name = models.CharField(max_length=255)

# That's now the name of the reverse filter
article_instance.*filter*(tag__name="important")

However, an object model doesn't have filter() method. I am trying to use 
related_query_name to filter a model M with a condition on the related 
objects R. The problem is that result includes instances of M which don't 
have related objects in R. But I would like to first understand what 
related_query_name is. Could someone explain? Thanks,

Petr

-- 
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/086400af-967e-45ea-a413-4ca4fcaf17a9%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-29 Thread amarshall
I see now that I think the best course of action is to get the traceback by 
adding the ADMINS settings. So I did that. Now I need to restart the uwsgi 
server process. Any suggestions on how to kind of brute force do that right 
now? 

I see on their site they suggest "uwsgi --reload /tmp/project-master.pid". 
I see this everywhere but no where has any site/tut said "create a 
project-master.pid file for  reasons".  I'm assuming it's supposed 
to contain a list of all the uwsgi worker processes? I created a blank file 
at that directory and tried to run my command to start the service over 
again adding the "pidfile=/tmp/project-master.pid" tag and I go to check 
the file and nothing is there. So I'm not sure if the uwsgi command is 
restarting . All so I can see and get my traceback.. Sorry about this 
tanget. 

On Thursday, August 28, 2014 8:22:00 PM UTC-4, 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/95ab3aad-77aa-4bc4-a614-540a3d23ff2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help Django

2014-08-29 Thread Cassiano Monego
Thank you Collin.

Em sexta-feira, 29 de agosto de 2014 16h49min37s UTC-3, Collin Anderson 
escreveu:
>
> https://docs.djangoproject.com/en/dev/intro/tutorial01/#creating-models
>

-- 
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/3fb4c05a-5182-4f81-a116-48cc79767926%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-29 Thread amarshall
I didn't have my uwsgi setup to log. So I did with this command : 

uwsgi --socket :8001 --wsgi-file wsgi.py --master --processes 5 --threads 2 
--daemonize /var/log/uwsgi/lokalapp.log


So I went to the site to reach the 500 error to see if anything updates and 
nothing is updated in the log file when I check it.

This is the only thing it logs: 

*** Starting uWSGI 2.0.6 (64bit) on [Fri Aug 29 15:43:09 2014] ***
compiled with version: 4.8.2 on 24 July 2014 15:50:13
os: Linux-3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014
nodename: web01
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /var/www/lokalapp.co
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your processes number limit is 15802
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
probably another instance of uWSGI is running on the same address (:8001).
bind(): Address already in use [core/socket.c line 759]
*** Starting uWSGI 2.0.6 (64bit) on [Fri Aug 29 15:45:57 2014] ***
compiled with version: 4.8.2 on 24 July 2014 15:50:13
os: Linux-3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014
nodename: web01
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /var/www/lokalapp.co
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your processes number limit is 15802
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
probably another instance of uWSGI is running on the same address (:8001).
bind(): Address already in use [core/socket.c line 759]


So, it doesn't show anything. Also, at first I was running that command 
without the --daemonize tag. Since I have I can't kill the server to 
restart it. Wanted to try to kill it with "kill -9 [process id] " but when 
I do another process comes in it's place. 


On Friday, August 29, 2014 11:59:11 AM UTC-4, amarshall wrote:
>
> I'm pretty sure my ALLOWED_HOST is setup right to allow all url locations 
> after the main domain.  I have not setup the EMAIL to send me notifications 
> upon 500 server error. Will do now.  About to check my uwsgi log and post 
> it as well

-- 
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/3273b9da-e7aa-41b6-a18b-32c0bd95b150%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help Django

2014-08-29 Thread Collin Anderson
https://docs.djangoproject.com/en/dev/intro/tutorial01/#creating-models

-- 
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/CAFO84S6LrWDrTvwsE529CS3FRmY_nuh6nnVo-r8DmaADfYBOsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help Django

2014-08-29 Thread Cassiano Monego
you have any examples of how to do this procedure?



Em sexta-feira, 29 de agosto de 2014 16h01min36s UTC-3, Collin Anderson 
escreveu:
>
> the general way is to have a "rule" model with a foreign key to your main 
> model, then use an inline in the admin
>

-- 
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/a7d16da3-c977-4971-8f11-a75c9f435866%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help Django

2014-08-29 Thread Cassiano Monego

você tem algum exemplo de como fazer este procedimento?



Em sexta-feira, 29 de agosto de 2014 16h01min36s UTC-3, Collin Anderson 
escreveu:
>
> the general way is to have a "rule" model with a foreign key to your main 
> model, then use an inline in the admin
>

-- 
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/64a7f1b1-22a6-43f4-bf36-be48961312a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How quickly do Django unit tests run?...

2014-08-29 Thread Fred Stluka

Benjamin,

I solved my problem.  I switched to SQLite for testing and now
run 500+ tests in 30 secs instead of 75 minutes.  Much better!

Thanks for your help!
--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 8/27/14 5:22 PM, Benjamin Scherrey wrote:

Postgres. best of luck.


On Thu, Aug 28, 2014 at 4:16 AM, Fred Stluka > wrote:


Ben,

Thanks!  That's exactly the kind of ballpark figure I wanted.

Sounds like I should be expecting roughly 5-10 tests/sec, plus
maybe 10-20 secs DB setup/migration.  I'm currently seeing 1
test per 7-9 secs, plus 50-60 secs DB setup time (syncdb, not
South, since I'm setting SOUTH_TESTS_MIGRATE = False).

Yeah, something must be wrong here.  I'm running 100X slower
than expected.

BTW, are those numbers using SQLite, MySQL, PostgreSQL, other?
So far, I'm using MySQL, running locally on a pretty fast Mac laptop.
I'm planning to switch to SQLite for testing, to make it run faster,
but haven't gotten that to work yet.

My next steps will be try again with SQLite, and perhaps get the
test suite to run in the PyCharm debugger so I can step through
the code and see where all the time is going.

Thanks again!

--Fred

Fred Stluka -- mailto:f...@bristle.com --
http://bristle.com/~fred/ 
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 8/27/14 4:21 PM, Benjamin Scherrey wrote:

Clearly that depends on what your tests do. One of our projects
runs ~400 tests in about a minute. If your tests do much database
access or have complex setUp/tearDown then that's not going to be
as fast of course. The Django 1.7 project I'm working on at the
moment takes a total of 12.7 seconds to complete but most of that
time is the setup and migrations execution for the test db. Once
it starts the 36 tests I have now complete in 3.58 seconds in
verbose mode with full branch coverage turned on.

coverage run --branch
--source="partner,item,utils,importing,channel" manage.py test
--verbosity=2 && coverage report --show-missing

-- Ben


On Thu, Aug 28, 2014 at 3:13 AM, Fred Stluka > wrote:

Benjamin,

OK, Thanks!  So roughly how fast would you expect?  Hundreds
of trivial tests per minute?  Thousands per minute?

Thanks!
--Fred

Fred Stluka -- mailto:f...@bristle.com --
http://bristle.com/~fred/ 
Bristle Software, Inc -- http://bristle.com -- Glad to be of
service!
Open Source: Without walls and fences, we need no Windows or
Gates.

On 8/27/14 3:57 PM, Benjamin Scherrey wrote:

Something's definitely wrong. Except for the initial setup
for the test run (in 1.7 migrations run each time for
example), the individual tests should execute as fast as any
normal python unit test.


On Wed, Aug 27, 2014 at 9:06 PM, Fred Stluka
> wrote:

How quickly do Django unit tests run?

Mine are taking 7-9 seconds each, even for trivial tests
like:
self.assertEqual(1 + 1, 2)
that are all in the same test class of the same app.

Is this typical?  Or do I have something misconfigured.

Thanks!
--Fred

-- 
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/53FDE5E7.6040506%40bristle.com.
For more 

Re: Help Django

2014-08-29 Thread Collin Anderson
the general way is to have a "rule" model with a foreign key to your main 
model, then use an inline in the admin

-- 
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/1bc2ca09-f482-44fa-b6a1-4ca193e6d738%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error importing dbapi2 (SOLVED)...

2014-08-29 Thread Fred Stluka

I figured it out.

Details:

I had set environment variable PYTHONPATH to help Django
find the sql_server.pyodbc files needed to make a connection
to a Microsoft SQL Server DB.  This was keeping SQLite from
working properly.  When I cleared the environment variable,
SQLite works fine.

I now get no errors when I do:
>>> import sqlite3
>>> from sqlite3 import dbapi2

and I no longer get the error about dbapi2 when I run my
regression tests via Django.

To get the sql_server.pyodbc file to be found, I now use a
symlink:
% ln -s django/db/backends/sql_server \
~/python/virtualenvs/hhl/lib/python2.7/site-packages/sql_server
instead of setting PYTHONPATH:
% setenv PYTHONPATH 
~/python/virtualenvs/hhl/lib/python2.7/site-packages/django/db/backends


FYI,
--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 8/25/14 9:30 AM, Fred Stluka wrote:

I'm getting error:

django.core.exceptions.ImproperlyConfigured:
Error loading either pysqlite2 or sqlite3 modules
(tried in that order): cannot import name dbapi2

Any suggestions?

Details:

My settings.py contains:
DATABASE = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/Users/fred/fred/HHL/HHLWeb/sqlite3.db'
}
}

Works fine with other DBs (MySQL, MS SQL Server, etc.), but now
I'm trying to switch to SQLite for faster testing.

From the command line, I can see that sqlite3 is installed
(by default as part of the Django install), but seems to not
contain dbapi2:

>>> import sqlite3
>>> from sqlite3 import dbapi2
Traceback (most recent call last):
  File "", line 1, in 
ImportError: cannot import name dbapi2

Any ideas for me?  Any suggestions on how to narrow down
the problem?  Any more info I should give you?

Thanks!
--Fred



--
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/5400CD39.400%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to call django web page with ordinary html page

2014-08-29 Thread Babatunde Akinyanmi
Why are you adding a csrf token in your context?
On 29 Aug 2014 13:05, "Pawan Soni"  wrote:

> Hi ,
>
> i have a simple html page,*p.html *which is not made in django
> application ,its just a ordinary html page  which look like..
>
> 
> 
> http://127.0.0.1:8000/test/; method="post">
> 
> 
> 
> 
>
> In form's action i am passing the path of my django url..
>
> this is my *urls.py* file..
>
>  from django.conf.urls import patterns, include, url
> from django.contrib import admin
> from login import views
>   urlpatterns = patterns('',
>url(r'^test',views.paymentcheck_view,name="test"),
>)
>
> my *views.py.*.
>
>  def paymentcheck_view(request):
>if request.method == "POST":
> c = {}
> c.update(csrf(request))
> return render_to_response('login1/create_pay_page.html',c)
>else:
> return HttpResponse('GET')
>
> Error i got ...
>
> Forbidden (403)
>
> CSRF verification failed. Request aborted.
> 
>
> i am stuck over here,pls help me
>
> Thnx 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/2b21261b-c48f-43d2-8db0-810b0c7a9c02%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%2BWjgXOXZp59r%2BHup7rHzZraH%3Dp%2BE%3DNTOHigX6za7OWonCw%3D-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Help Django

2014-08-29 Thread Cassiano Monego
Good Afternoon Everyone,

I am Working with Django the little time and I'm facing a problem. I need 
to create a form in the admin module of my project, and this record I have 
a field called RULE. where I can register a field called RULE, RULE put the 
field can have 1 or N records. My question is this, how do I create a RULE 
field where the user can add more fields as necessary RULE?

For example:

Rule:   xxx.xxx.xxx.xxx (add more fields RULE)
   xxx.xxx.xxx.xxx
   xxx.xxx.xxx.xxx
   ...

I count on your help.

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/aa5c2165-60fb-4014-845e-362bbce05a1c%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-29 Thread amarshall
I'm pretty sure my ALLOWED_HOST is setup right to allow all url locations after 
the main domain.  I have not setup the EMAIL to send me notifications upon 500 
server error. Will do now.  About to check my uwsgi log and post it as well

-- 
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/00d70175-5d1e-4c3e-8962-b42956f013e8%40googlegroups.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-29 Thread Yo-Yo Ma
I use mock for every testcase I have in my app (no queries in my entire 
test suite), but sometimes I also need to include a real model (but no 
queries or db), due to the complexity of the situation (e.g., relying on a 
bit more of Django's inner workings without having to mock 10-15 methods). 
In other words, despite unit tests being very controlled and specific to a 
few lines of code, sometimes I need to allow some infrastructure to run, in 
order to keep my tests simple, and more importantly, to keep them forward 
compatible.

To reiterate, I'm aware that, in a perfect world, the required components 
would just be mocked, but for my 9 test methods, I would have more than 
doubled the length of the tests and been left with an unreadable mess.

Here's the solution I came up with last night, after asking the question: 
https://gist.github.com/anonymous/a11898d0cd8ffc78b531 
(get_model(, ) was messier, due to the need for exception 
handling).

On Friday, August 29, 2014 10:57:05 AM UTC-4, Alex Chiaranda wrote:
>
> Hi, can't you guys mock these models ?
>
> On Thursday, August 28, 2014 9:31:04 PM UTC-3, Yo-Yo Ma wrote:
>>
>> 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/5cad5371-3a23-4f53-bc84-41a809976f04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Guidance needed - Real time and django

2014-08-29 Thread Aamu Padi
Hello,
I would like to build a real time web application, but have little idea of
where to start to from. It will have notification and feed system like
facebook or instagram. Would really appreciate if anyone who have already
done this type of web application could kindly guide me through. I will be
very grateful.

Thank you.

-- 
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/CAHSNPWuiOJ5m%3DcCUFOc-j%3DRR3LHSAOyhd4Uk7HOaR78cQB-V4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to call django web page with ordinary html page

2014-08-29 Thread Matt Gushee
On Fri, Aug 29, 2014 at 6:16 AM, Shubham Pansari
 wrote:
> You are missing csrf_token which is set by request for csrf verification.
> After the line
> http://127.0.0.1:8000/test/; method="post">
> in your code put {%csrf_token%} and it should work fine

I'm a Django newbie, so I could well be mistaken, but I don't think
that will work. The OP said it was plain HTML; that means Django
doesn't process it, so Django template tags won't work. But it looks
like Flatpages might help:
http://www.djangobook.com/en/2.0/chapter16.html.

--
Matt Gushee

-- 
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/CABrD0ed5HGNC%2BVbz3urmaJNEpYVWSdbjKmu86F4rkENL3DydDQ%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-29 Thread Alex Chiaranda
Hi, can't you guys mock these models ?

On Thursday, August 28, 2014 9:31:04 PM UTC-3, Yo-Yo Ma wrote:
>
> 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/b1d86fe6-717b-4bfd-ad54-bfcbcee83991%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-29 Thread Collin Anderson
is your ALLOWED_HOSTS set correctly?

it's also possible to set up  ADMINS and email settings so you get an email 
with details about the server 500 error.

Does your uWSGI log show any more info?

-- 
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/10c5a3f5-c283-4424-a63a-7bb138cd2f51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to call django web page with ordinary html page

2014-08-29 Thread Shubham Pansari
You are missing csrf_token which is set by request for csrf verification.
After the line
http://127.0.0.1:8000/test/; method="post">
in your code put {%csrf_token%} and it should work fine and also read why
it didnot worked without it from
https://docs.djangoproject.com/en/dev/ref/contrib/csrf/  . This should
answer all your queries.


On Fri, Aug 29, 2014 at 4:36 PM, Pawan Soni  wrote:

> Hi ,
>
> i have a simple html page,*p.html *which is not made in django
> application ,its just a ordinary html page  which look like..
>
> 
> 
> http://127.0.0.1:8000/test/; method="post">
> 
> 
> 
> 
>
> In form's action i am passing the path of my django url..
>
> this is my *urls.py* file..
>
>  from django.conf.urls import patterns, include, url
> from django.contrib import admin
> from login import views
>   urlpatterns = patterns('',
>url(r'^test',views.paymentcheck_view,name="test"),
>)
>
> my *views.py.*.
>
>  def paymentcheck_view(request):
>if request.method == "POST":
> c = {}
> c.update(csrf(request))
> return render_to_response('login1/create_pay_page.html',c)
>else:
> return HttpResponse('GET')
>
> Error i got ...
>
> Forbidden (403)
>
> CSRF verification failed. Request aborted.
> 
>
> i am stuck over here,pls help me
>
> Thnx 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/2b21261b-c48f-43d2-8db0-810b0c7a9c02%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/CAOdEGu3AxhqBMaHBsfw8-qb5RvHj0ATt3CPtoptBDyubQUJW-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Cannot start tutorial that begins with '"jango-admin.py startproject mysite"

2014-08-29 Thread Jo MM
Hello.
I believe I have successfully installed Django based on having no problems 
with testing "import django" at the command prompt and in the Python 
interpreter.
However, I cannot get the tutorial started. 
As explained by the tutorial ("From the command line, cd into a directory 
where you’d like to store your code, then run the following command:
django-admin.py startproject mysite") I cd over to: C:\Users\John. When I 
type "django-admin . . ." nothing happens. "mysite" is not created.
I have looked at group messages. One thing I notice is that I appear to be 
missing "Lib\site-packages\django\bin", but I don't know how to 
find/download this.
Also, at the command prompt when I cd to Python27\Scripts and enter 
"django-admin.py 
startproject mysite" I get "Import Error: No module named django.core".

My set-up:
1. Windows 7 32-bit
2. C:\Python27\Scripts\django-admin.py
3. End portion of my System Path as shown in Environmental Variables: . . 
;C:\Python27\Scripts; 
C:\Python27\Lib\site-packages\django\bin; 
C:\Python27\Scripts\django-admin.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/7df34208-487d-41b7-87a4-646d9b883ad6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Code: Add context to trans blocks

2014-08-29 Thread Patrick Robertson
Hi all,

Do you have any 'best practices' for translating Django?
It's just come to my attention that in a couple of places, it would be good 
to add some context to certain translations. I just thought I'd ask to see 
if you've discussed it before

A good example is the word 'Save' used in the Django admin to save an 
object to the database (after editing).
In English save has (at least) two meanings, another being to 'save' money. 
(Buy 2 SAVE $5). This brings up a few complcations when translating the 
site to languages which use different words for each context.

Would there be any objections to me adding context to these two places and 
creating a PR?

#: contrib/admin/templates/admin/pagination.html:11
#: contrib/admin/templates/admin/submit_line.html:3

Cheers

-- 
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/2c98d7df-77e7-40ef-a56e-fa8b4ad4fe23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django framework plugin

2014-08-29 Thread Pawan Soni


Hi,

I am trying to create a Django application as a plugin to integrate with 
other Django framework applications or websites (for example: a Payment 
gateway plugin).  My application has package hierarchy as mentioned below.



DjangoProject   

|=> Djangowork

|templates 

|=>_*inti*_.py

|settings.py

|   urls.py

|wsgi.py

| views.py

   |=>manage.py

 

I have already implemented the functionalities for the application but I am 
unable to convert the package into a plug-in. Is there a way to convert it 
into a plug-in, to be used with other Django websites or applications? If 
not as a plug-in, what would be other ways to accomplish such tasks?

I will be grateful for any help regarding the queries I have. 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/c90c2413-f589-4d36-9df6-f0c0ca8f2163%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to call django web page with ordinary html page

2014-08-29 Thread Pawan Soni
Hi ,

i have a simple html page,*p.html *which is not made in django application 
,its just a ordinary html page  which look like..



http://127.0.0.1:8000/test/; method="post">





In form's action i am passing the path of my django url..

this is my *urls.py* file..

 from django.conf.urls import patterns, include, url
from django.contrib import admin
from login import views
  urlpatterns = patterns('',
   url(r'^test',views.paymentcheck_view,name="test"),
   )

my *views.py.*.

 def paymentcheck_view(request):
   if request.method == "POST":
c = {}
c.update(csrf(request))
return render_to_response('login1/create_pay_page.html',c)
   else:
return HttpResponse('GET')

Error i got ...

Forbidden (403)

CSRF verification failed. Request aborted.


i am stuck over here,pls help me 

Thnx 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/2b21261b-c48f-43d2-8db0-810b0c7a9c02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django ORM generate inefficient SQL

2014-08-29 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.