Re: Django explicit `order_by` by ForeignKey field

2014-04-25 Thread Simon Charette
Actually the FieldError is not raised anymore in Django 1.7 (and master) 
and issuing a .order_by('group_id') is the equivalent of .order_by('group') 
which respect related model ordering if defined.

I would argue we should seize the opportunity to provide a way of opting 
out of this default behavior while maintaining backward compatibility by 
shipping this in Django 1.7.

I'm afraid that if we wait until 1.7 is released with this *fix* we'll have 
to provide an extra api to .order_by (say follow=False) to fix this 
correctly.

We should move this discussion forward to django-developers in order to get 
feedback from the community.

Simon

Le vendredi 25 avril 2014 18:50:55 UTC-4, alTus a écrit :
>
> Hi. So I have some small models:
>
> class Group(models.Model):
> name = models.CharField()
> 
> class Meta:
> ordering = ('name',)
>
> class Entity(models.Model):
> name = models.CharField()
> group = models.ForeignKey(Group, null=True)
>
> Now I want to perform a really simple query like this:
>
> SELECT * FROM `app_entity`
> WHERE `app_entity`.`name` = 'something'
> ORDER_BY `app_entity`.`group_id` ASC;
>
> Note that I really want to order by the field itself with no useless joins 
> or smth else. So I write smth like that:
>
> Entity.objects.filter(name='something').order_by('group')
>
> and django happily makes this query:
>
> SELECT `app_entity`.`id` FROM `app_entity`
> LEFT OUTER JOIN `app_group` ON ( `app_entity`.`group_id` = 
> `app_group`.`id` )
> WHERE `app_entity`.`name` = 'smth' 
> ORDER BY `app_group`.`name` ASC
>
> According to the docs it uses default Group model ordering and this 
> default behaviour makes sense.
> And I need this ordering to be set (for admin and some other places).
> If I don't set ordering param in Group.Meta - I get what I want: explicit 
> query shown above (1st one).
> But as I said I need it. And I just can't get this query easily.
> So we have some sort of inconsistant behaviour - I can do the right thing 
> without ordering param and I can't do it with it.
>
> order_by('group_id') doesn't work and raises FieldError.
> For now I'm using extra(order_by=['app_entity.group_id']) or even 
> order_by('app_entity.group_id') but it's quite ugly and it's still such a 
> trivial thing that should have a simple and straight ORM solution.
>
> As I think this might be considered as a bug or smth. In django sourses I 
> found some place where field names lile `group_id` work.
> For example, `values_list` method. But this behaviour is marked as a hack 
> there.
>
> So the first question is whether do I miss smth and it can be done somehow.
> And the second, if not, do I need to submit a ticket for 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/faee8e07-c6f8-4fd0-b8ce-379a39398fc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django explicit `order_by` by ForeignKey field

2014-04-25 Thread Simon Charette
The issue was referenced in 
#19195and it was suggested we add 
the ability to order by field name and not only 
by attribute name.

I suggest you open a ticket for this and add a reference to it in 
#19195
.

In the mean time you can get the correct ordering by issuing a 
order_by('group__pk') but you'll have to live with the extraneous JOIN.

Thanks,
Simon

Le vendredi 25 avril 2014 18:50:55 UTC-4, alTus a écrit :
>
> Hi. So I have some small models:
>
> class Group(models.Model):
> name = models.CharField()
> 
> class Meta:
> ordering = ('name',)
>
> class Entity(models.Model):
> name = models.CharField()
> group = models.ForeignKey(Group, null=True)
>
> Now I want to perform a really simple query like this:
>
> SELECT * FROM `app_entity`
> WHERE `app_entity`.`name` = 'something'
> ORDER_BY `app_entity`.`group_id` ASC;
>
> Note that I really want to order by the field itself with no useless joins 
> or smth else. So I write smth like that:
>
> Entity.objects.filter(name='something').order_by('group')
>
> and django happily makes this query:
>
> SELECT `app_entity`.`id` FROM `app_entity`
> LEFT OUTER JOIN `app_group` ON ( `app_entity`.`group_id` = 
> `app_group`.`id` )
> WHERE `app_entity`.`name` = 'smth' 
> ORDER BY `app_group`.`name` ASC
>
> According to the docs it uses default Group model ordering and this 
> default behaviour makes sense.
> And I need this ordering to be set (for admin and some other places).
> If I don't set ordering param in Group.Meta - I get what I want: explicit 
> query shown above (1st one).
> But as I said I need it. And I just can't get this query easily.
> So we have some sort of inconsistant behaviour - I can do the right thing 
> without ordering param and I can't do it with it.
>
> order_by('group_id') doesn't work and raises FieldError.
> For now I'm using extra(order_by=['app_entity.group_id']) or even 
> order_by('app_entity.group_id') but it's quite ugly and it's still such a 
> trivial thing that should have a simple and straight ORM solution.
>
> As I think this might be considered as a bug or smth. In django sourses I 
> found some place where field names lile `group_id` work.
> For example, `values_list` method. But this behaviour is marked as a hack 
> there.
>
> So the first question is whether do I miss smth and it can be done somehow.
> And the second, if not, do I need to submit a ticket for 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/cab3da8e-b88b-4e2e-b4fb-febb411ae658%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django explicit `order_by` by ForeignKey field

2014-04-25 Thread alTus
Hi. So I have some small models:

class Group(models.Model):
name = models.CharField()

class Meta:
ordering = ('name',)

class Entity(models.Model):
name = models.CharField()
group = models.ForeignKey(Group, null=True)

Now I want to perform a really simple query like this:

SELECT * FROM `app_entity`
WHERE `app_entity`.`name` = 'something'
ORDER_BY `app_entity`.`group_id` ASC;

Note that I really want to order by the field itself with no useless joins 
or smth else. So I write smth like that:

Entity.objects.filter(name='something').order_by('group')

and django happily makes this query:

SELECT `app_entity`.`id` FROM `app_entity`
LEFT OUTER JOIN `app_group` ON ( `app_entity`.`group_id` = `app_group`.`id` 
)
WHERE `app_entity`.`name` = 'smth' 
ORDER BY `app_group`.`name` ASC

According to the docs it uses default Group model ordering and this default 
behaviour makes sense.
And I need this ordering to be set (for admin and some other places).
If I don't set ordering param in Group.Meta - I get what I want: explicit 
query shown above (1st one).
But as I said I need it. And I just can't get this query easily.
So we have some sort of inconsistant behaviour - I can do the right thing 
without ordering param and I can't do it with it.

order_by('group_id') doesn't work and raises FieldError.
For now I'm using extra(order_by=['app_entity.group_id']) or even 
order_by('app_entity.group_id') but it's quite ugly and it's still such a 
trivial thing that should have a simple and straight ORM solution.

As I think this might be considered as a bug or smth. In django sourses I 
found some place where field names lile `group_id` work.
For example, `values_list` method. But this behaviour is marked as a hack 
there.

So the first question is whether do I miss smth and it can be done somehow.
And the second, if not, do I need to submit a ticket for 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/c7ff4b2f-da66-40e8-b83d-5135efe81e0b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django

2014-04-25 Thread Lee
In case you dont see my email, I copy my reply here too:

Hi, 

Your problem is in the results view function. I'm not sure what version of 
the tutorial you are following, but assuming you are using Django 1.6, the 
following:

def results(request, poll_id):
poll = get_object_or_404(Poll, poll_id)
return render(request, 'poll/results.html', {'poll':poll})

Should be:

def results(request, poll_id):
poll = get_object_or_404(Poll, pk=poll_id)
return render(request, 'poll/results.html', {'poll':poll})

Hope it helps. 

On Saturday, 19 April 2014 07:07:38 UTC+1, Srinivasulu Reddy wrote:
>
>
> Hello folks,
>  I am new to python/django . i am earning myself i want to 
> know effective way of learning python / django . i am following django book 
> for django .  Light bird apps also.
>
> So please anyone can help me to find the good way learn the python / 
> django . I love to learn the python / django .
>
>

-- 
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/c642a22d-e1be-4397-a154-4323e378bd2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Interesting Django project folder structure.

2014-04-25 Thread Damián Pérez
Hello,

I read that the folder *apps* itsn't recomended.

You can see this structure: https://github.com/damianpv/skeleton_django

Best regards,



On Thursday, April 24, 2014 11:41:54 AM UTC-5, Perry Arellano-Jones wrote:
>
> It's mostly preference, use what suits you.  I prefer having all of my 
> apps in an 'apps' directory for organization's sake.  I may not have an 
> issue keeping track of them now, but if a project gets large it could get 
> unruly.  Anyone else that wants to contribute to any of my projects may 
> benefit from the clarity as well. To create a new app in a subdirectory, 
> all you need to do is specify the path with startapp. Simple example from 
> your project root:
>
> mkdir -p ./apps/new_app
>
> ./manage.py startapp new_app ./apps/new_app
>
>  
>
>
> On Monday, April 21, 2014 9:33:48 AM UTC-7, Tianyi Wang wrote:
>>
>> Hi,
>>
>> Cool. But I see it'd work pretty nicely when you have many custom apps 
>> and libs.
>>
>> When you do "./manage.py startapp newapp", Django create the "newapp" as 
>> the layout I'm using.
>> AndI have a Django site which contains four Custom apps. The layout I'm 
>> using works fine. Just wonder is there
>> any other benefits to change to the suggested layout?
>>
>> Cheers 
>>
>> On Monday, 21 April 2014 15:04:42 UTC+1, Mrinmoy Das wrote:
>>>
>>> Hi,
>>>
>>> The suggested folder structure is the standard stuff that is generally 
>>> used. I personally and all the teams I have worked with uses this 
>>> particular structure.
>>>
>>> sent form mobile, apologies for the brevity
>>> On Apr 21, 2014 7:30 PM, "Tianyi Wang"  wrote:
>>>
>>> Today I was reading through 
>>> http://www.deploydjango.com/django_project_structure (great resource)
>>>
>>> The suggested folder structure for a Django project from this site is 
>>> like below:
>>> (I'm only interested in layout for Django apps, not requirements files 
>>> or settings files)
>>>
>>> myproject
>>> |-- manage.py
>>>
>>> |-- requriements.txt
>>> |-- *myproject*
>>> |-- __init__.py
>>>
>>> |-- settings.py
>>> |-- urls.py
>>> |-- wsgi.py
>>>
>>> |
>>> `-- *apps*
>>>
>>> |-- __init__.py
>>>
>>> |-- *app_one*
>>>
>>> |   |-- __init__.py
>>> |   |-- models.py
>>> |   |-- views.py
>>> |   `-- urls.py
>>> `-- *app_two*
>>> |-- __init__.py
>>> |-- models.py
>>> |-- views.py
>>> `-- urls.py
>>>
>>>
>>> My current setup is like below:
>>>
>>> myproject
>>> |-- manage.py
>>>
>>> |-- requirements.txt
>>> |-- *myproject*
>>> |   |-- __init__.py
>>> |   |-- settings.py
>>> |   |-- urls.py
>>> |   `-- wsgi.py
>>> `-- *app_one*
>>> |   |-- __init__.py
>>> |   |-- models.py
>>> |   |-- views.py
>>> |   `-- urls.py
>>> `-- *app_two*
>>> |-- __init__.py
>>> |-- models.py
>>> |-- views.py
>>> `-- urls.py
>>>
>>>
>>> The reason for the first layout is to categorise the apps, 
>>>
>>> so one can have a "apps" folder contains all the custom apps;
>>>
>>> "libs" folder contains all the lib/helper apps and such.
>>>
>>>
>>> Do you guys think it's a good idea? 
>>>
>>>
>>> Cheers
>>>
>>>
>>> Tianyi  
>>>
>>>  -- 
>>> 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/37ecd6cb-6dcc-431e-ae39-3814dbf647de%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/24b43a9a-8804-4ccf-b672-135398da0f43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Http request with multiple files is not able to read by django server

2014-04-25 Thread Erik Cederstrand
Den 25/04/2014 kl. 14.39 skrev kousik chowdhury :

> After going through all the links related to this problem, I come to know 
> that this problem may happen because of the **broken request** That is if 
> someone cancelled the request in between.
> 
> As my request is an `AsyncTask` to the request should not break.

Clients can still abort the request or close the connection in many ways - the 
client application crashing, the device crashing, shutting down or running out 
of battery, losing network connection or switching networks etc.

You should probably just ignore these errors unless you suspect the error is 
happening despite any of the above reasons.

Erik

-- 
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/F66FD1CA-855F-448B-8E18-53A09601C2BC%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


RE: Http request with multiple files is not able to read by django server

2014-04-25 Thread Ilya Kazakevich
Hello,


There may be some web-proxy between client and server that limits request size 
or time. Server may limit it as well.

* Remove all proxies between client and server
* Try to use different client (browser for example)
* Check your server configuration for request size and timeout.


Ilya Kazakevich,
JetBrains PyCharm (Best Python/Django IDE)
http://www.jetbrains.com/pycharm/
"Develop with pleasure!"

>-Original Message-
>From: django-users@googlegroups.com
>[mailto:django-users@googlegroups.com] On Behalf Of kousik chowdhury
>Sent: Friday, April 25, 2014 4:39 PM
>To: django-users@googlegroups.com
>Subject: Http request with multiple files is not able to read by django server
>
>I am trying to send multiple files(images and audio) from an android device 
>using
>`MultipartEntityBuilder` (java) with http request. Everytime request including
>files reaches server and is working as expected but sometimes(10%) django
>server is not able to read the content of the request.
>
>After going through all the links related to this problem, I come to know that 
>this
>problem may happen because of the **broken request** That is if someone
>cancelled the request in between.
>
>As my request is an `AsyncTask` to the request should not break.
>
>
>> I know this question is already asked. As I didn't get a proper solution from
>these posts, I want to reopen the issue. So instead of making this as
>`duplicate` ,please try to give me some light.
>
>Links: -
>
> -
>http://stackoverflow.com/questions/15544124/django-unreadableposterror-req
>uest-data-read-error
>
> -
>http://stackoverflow.com/questions/3823280/ioerror-request-data-read-error/7
>089413
>
>
>
>
>
>Server Log:
>
>Traceback (most recent call last):
>  File "/var/www/html/prototype/version1/views.py", line 2515, in
>manage_app_data
>print request.FILES
>  File
>"/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 
>165,
>in _get_files
>self._load_post_and_files()
>  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", 
> line
>215, in _load_post_and_files
>self._post, self._files = self.parse_file_upload(self.META, data)
>  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", 
> line
>180, in parse_file_upload
>return parser.parse()
>  File
>"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line
>140, in parse
>for item_type, meta_data, field_stream in Parser(stream,
>self._boundary):
>  File
>"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line
>598, in __iter__
>for sub_stream in boundarystream:
>  File "/usr/local/lib/python2.7/site-packages/django/utils/six.py", line 
> 473,
>in next
>return type(self).__next__(self)
>  File
>"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line
>415, in __next__
>return LazyStream(BoundaryIter(self._stream, self._boundary))
>  File
>"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line
>441, in __init__
>unused_char = self._stream.read(1)
>  File
>"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line
>315, in read
>out = b''.join(parts())
>  File
>"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line
>308, in parts
>chunk = next(self)
>  File "/usr/local/lib/python2.7/site-packages/django/utils/six.py", line 
> 473,
>in next
>return type(self).__next__(self)
>  File
>"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line
>330, in __next__
>output = next(self._producer)
>  File "/usr/local/lib/python2.7/site-packages/django/utils/six.py", line 
> 473,
>in next
>return type(self).__next__(self)
>  File
>"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line
>391, in __next__
>data = self.flo.read(self.chunk_size)
>  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", 
> line
>244, in read
>six.reraise(UnreadablePostError, UnreadablePostError(*e.args),
>sys.exc_info()[2])
>  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", 
> line
>242, in read
>return self._stream.read(*args, **kwargs)
>  File
>"/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 51,
>in read
>result = self.buffer + self._read_limited(size - len(self.buffer))
>  File
>"/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 39,
>in _read_limited
>result = self.stream.read(size)
>UnreadablePostError: request data read error
>
>
>How to fix ? what is going wrong?
>
>
>--
>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

Http request with multiple files is not able to read by django server

2014-04-25 Thread kousik chowdhury
I am trying to send multiple files(images and audio) from an android device 
using `MultipartEntityBuilder` (java) with http request. Everytime request 
including files reaches server and is working as expected but 
sometimes(10%) django server is not able to read the content of the request.

After going through all the links related to this problem, I come to know 
that this problem may happen because of the **broken request** That is if 
someone cancelled the request in between.

As my request is an `AsyncTask` to the request should not break.


> I know this question is already asked. As I didn't get a proper solution 
from these posts, I want to reopen the issue. So instead of making this as 
`duplicate` ,please try to give me some light.

Links: - 

 - 
http://stackoverflow.com/questions/15544124/django-unreadableposterror-request-data-read-error

 - 
http://stackoverflow.com/questions/3823280/ioerror-request-data-read-error/7089413





Server Log:

Traceback (most recent call last):
  File "/var/www/html/prototype/version1/views.py", line 2515, in 
manage_app_data
print request.FILES
  File 
"/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 
165, in _get_files
self._load_post_and_files()
  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", 
line 215, in _load_post_and_files
self._post, self._files = self.parse_file_upload(self.META, data)
  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", 
line 180, in parse_file_upload
return parser.parse()
  File 
"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", 
line 140, in parse
for item_type, meta_data, field_stream in Parser(stream, 
self._boundary):
  File 
"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", 
line 598, in __iter__
for sub_stream in boundarystream:
  File "/usr/local/lib/python2.7/site-packages/django/utils/six.py", 
line 473, in next
return type(self).__next__(self)
  File 
"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", 
line 415, in __next__
return LazyStream(BoundaryIter(self._stream, self._boundary))
  File 
"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", 
line 441, in __init__
unused_char = self._stream.read(1)
  File 
"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", 
line 315, in read
out = b''.join(parts())
  File 
"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", 
line 308, in parts
chunk = next(self)
  File "/usr/local/lib/python2.7/site-packages/django/utils/six.py", 
line 473, in next
return type(self).__next__(self)
  File 
"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", 
line 330, in __next__
output = next(self._producer)
  File "/usr/local/lib/python2.7/site-packages/django/utils/six.py", 
line 473, in next
return type(self).__next__(self)
  File 
"/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", 
line 391, in __next__
data = self.flo.read(self.chunk_size)
  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", 
line 244, in read
six.reraise(UnreadablePostError, UnreadablePostError(*e.args), 
sys.exc_info()[2])
  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", 
line 242, in read
return self._stream.read(*args, **kwargs)
  File 
"/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 
51, in read
result = self.buffer + self._read_limited(size - len(self.buffer))
  File 
"/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 
39, in _read_limited
result = self.stream.read(size)
UnreadablePostError: request data read error


How to fix ? what is going wrong?

-- 
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/9f58b9cb-4ca6-48d6-aab4-649ec024142b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.