Re: Gunicorn sock file is missing?

2015-02-26 Thread Erik Cederstrand

> Den 26/02/2015 kl. 07.56 skrev Kaloian :
> 
> Hi Erik,
> 
> No it doesn't start at all, running the gunicorn_start script gives: 
> 
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Can't connect to /path/to/my/gunicorn.sock 
> 
> This is why I thought that the missing sock file is failing it to start. Do 
> you think it could be something else? 
> I have already tried to add the absolute path in gunicorn_start but nothing 
> changed. 

A UNIX socket is like a TCP connection, except it's represented as a file. 
gunicorn is supposed to create it on startup and destroy it on shutdown, and it 
shouldn't be present when gunicorn is not running.

Maybe you tried to create /path/to/my/gunicorn.sock yourself, and the file is 
now garbage? Try deleting it. Otherwise, another instance of gunicorn may be 
running already. Try "ps aux | grep gunicorn" or "lsof -U | grep gunicorn" if 
you're on Linux. Also, the user running gunicorn_start must have access to 
create files in /path/to/my/

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/091316F1-9473-4A28-B237-FAA8C371E169%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: how to put files in different dirs

2015-02-26 Thread Michael Pöhn
On 26.02.2015 02:30, 163 email wrote:
> yes , what i mean is "media files".
> there are so many file,may be several thousands ,to be uploaded
> from client to server. 
> if all files in one dir , it'll be slow. 
> but i don't find any way  put files in different dirs just using django.
> now i write a function to put  files in different dirs ,but it complex.
> is there any easy way ?
> Thanks !
> 
> 163 email

There is an easy way for accomplishing what you want mentioned in
djangos docs:

»For example, say your MEDIA_ROOT is set to '/home/media', and upload_to
is set to 'photos/%Y/%m/%d'. The '%Y/%m/%d' part of upload_to is
strftime() formatting; '%Y' is the four-digit year, '%m' is the
two-digit month and '%d' is the two-digit day. If you upload a file on
Jan. 15, 2007, it will be saved in the directory
/home/media/photos/2007/01/15.«

https://docs.djangoproject.com/en/1.7/ref/models/fields/#django.db.models.FileField.storage

-- 
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/54EEE445.9030409%40fsfe.org.
For more options, visit https://groups.google.com/d/optout.


Re: Edx LDAP Auth setting

2015-02-26 Thread 'Yip Terence' via Django users
Hi M and L,
 
Attached please find the output in /edx/var/log/lms/edx.log
Django can't to get the %user value.
 
 
Config:

AUTH_LDAP_USER_SEARCH = LDAPSearch('OU=Users', ldap.SCOPE_SUBTREE, 
"(&(mail=%(user)s))(objectClass=User)(objectCategory=person))")
-
 
Error MSG:
---
Feb 26 17:18:33 ethiopia 
[service_variant=lms][django_auth_ldap][env:sandbox] ERROR [ethiopia  3016] 
[config.py:166] - search_s('OU=Users', 2, 
'(&(mail=))(objectClass=User)(objectCategory=person))') raised 
FILTER_ERROR({'desc': 'Bad search filter'},)
---
 
Thanks and Regards,
Terence Yip

Yip Terence於 2015年2月26日星期四 UTC+8下午3時02分38秒寫道:

> Hi M,
>  
> Actually, I can connect with our AD server, but I need to hardcode the 
> user in the connection string so that I would like to ask for the solution 
> about how can I get the %user value and create the profile.  
>  
> Maybe I can paste my connection string here for more easy to understand.  
> I have been pasted the following code in 
> /edx/app/edxapp/edx-platform/lms/envs/common.py.  I can successful login to 
> edX when I hardcode the user in "AUTH_LDAP_USER_SEARCH".  Is that paste 
> the code in the wrong location? 
>  
>  
>
> ---
> import ldap
> from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, 
> PosixGroupType
> #AUTH_LDAP_START_TLS = True
> AUTH_LDAP_GLOBAL_OPTIONS = {
>  ldap.OPT_X_TLS_REQUIRE_CERT: False,
>  ldap.OPT_REFERRALS: False,
> }
> # Baseline configuration.
> AUTH_LDAP_SERVER_URI = "ldap://dc.abc.hk:389";
> AUTH_LDAP_BIND_DN = "CN=connection_account,OU=SystemAcct,DC=abc,DC=hk"
> AUTH_LDAP_BIND_PASSWORD = "password"
> user = request.user
> AUTH_LDAP_USER_SEARCH = LDAPSearch('OU=Users,DC=abc,DC=hk', 
> ldap.SCOPE_SUBTREE, "(&(
> mail=usern...@abc.hk)(objectClass=User)(objectCategory=person))")
>  
> AUTH_LDAP_ALWAYS_UPDATE_USER = True
> # Set up the basic group parameters.
> AUTH_LDAP_GROUP_SEARCH = LDAPSearch('OU=Users,DC=vtc,DC=hk', 
> ldap.SCOPE_SUBTREE, "(&(objectClass=User)(objectCategory=person))")
>  
> # set group type
> AUTH_LDAP_GROUP_TYPE = PosixGroupType()
> AUTH_LDAP_CONNECTION_OPTIONS = {
>  ldap.OPT_REFERRALS: 0,
> }
>  
> # Simple group restrictions
> #~ AUTH_LDAP_REQUIRE_GROUP = 
> "cn=enabled,ou=django,ou=groups,dc=example,dc=com"
> #~ AUTH_LDAP_DENY_GROUP = 
> "cn=disabled,ou=django,ou=groups,dc=example,dc=com"
> # Populate the Django user from the LDAP directory.
> AUTH_LDAP_USER_ATTR_MAP = {
>  "username": "cn",
>  "first_name": "givenName",
>  "last_name": "sn",
>  "email": "mail"
> }
>  
> AUTH_LDAP_PROFILE_ATTR_MAP = {
>  "name": "cn"
> }
>
> # important! to use the group's permission
> AUTH_LDAP_MIRROR_GROUPS = True
> # Use LDAP group membership to calculate group permissions.
> AUTH_LDAP_FIND_GROUP_PERMS = True
> # Cache group memberships for an hour to minimize LDAP traffic
> AUTH_LDAP_CACHE_GROUPS = True
> AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
>
> -
>  
> Looking for your reply.  Thanks!
>  
> Thanks and Regards,
> Terence Yip
>
> somecallitblues於 2015年2月24日星期二 UTC+8下午7時09分22秒寫道:
>
>> To check the version go to shell and run this:
>>
>> >>> import django_auth_ldap
>>
>> >>> django_auth_ldap.version
>>
>> (1, 1, 2)
>>
>> >>> 
>>
>> As for virtualenv, it's a good practice but it's not necessary. 
>>
>> By the way, have you tried performing a simple search on the LDAP server? 
>> I think that your best bet is to start with python-ldap (forget about 
>> django_auth_ldap), try to connect to the server, perform a bind and get a 
>> feel for it. 
>>
>> I normally open the shell and run something like this in it 
>> https://bpaste.net/show/d4348eb1b3dd
>>
>> You have to know the following:
>>
>> - protocol (secure or not)
>>
>> - IP or domain name of the LDAP server
>>
>> - port
>>
>> - A full DN of one of the users would be useful but once you establish 
>> the connection you can figure this out.
>>
>> I remember that I was using Django 1.5.x and django_auth_ldap was still 
>> using User model by default. Not sure if that's still the case but you may 
>> have to patch it.
>>
>> Good luck!
>>
>> M
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On 24 February 2015 at 17:37, 'Yip Terence' via Django users <
>> django...@googlegroups.com> wrote:
>>
>>> Hi L,
>>>
>>>  
>>>
>>> Thanks for your reply.
>>>
>>>  
>>>
>>> I’m through pip to install the django-auth-ldap already.  But there are 
>>> two question here. 
>>>
>>> 1.   How can I check the django-auth-ldap version?
>>>
>>> 2.   What do you mean of install via virt env? I’m follow the edX 
>>> Ubuntu 12.04 

Research: Translations od documentation

2015-02-26 Thread Tomáš Ehrlich
Hello,
tonight is regular python/ruby meetup in Brno (Czech republic) about 
documentation. Last few months I’ve been working on project concerning 
localization of documents. I would like to know your opinion about localization 
of documentation:

Do you think it would be useful to translate documentation of:
1) Django
2) Python
3) Any project documented using Sphinx (like numpy, scipy, request, …)

Three simple answers Yes/No would help me a lot. If you write a short paragraph 
about your opinion, I will very appreciate it.

Thank you


Cheers,
   Tom


-- 
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/29FE9B62-B01A-4843-B4EE-D4ED7B71ECD8%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can the new `Prefetch` solve my problem?

2015-02-26 Thread cool-RR
James, you misunderstood me.

There isn't supposed to be a `favorite_or_nearby_chairs` attribute. That's 
the new attribute I want the prefetching to add to the `Desk` queryset that 
I need. Also, I don't understand why you'd tell me to add a `
.select_related('nearby_desks')` to my query. Are you talking about the 
query that starts with `Chair.objects`? I'm not looking to get a `Chair` 
queryset. I'm looking to get a `Desk` queryset, which has a prefetched 
attribute `favorite_or_nearby_chairs` which contains the `Chair` queryset I 
wrote down.


Thanks,
Ram.

On Thursday, February 26, 2015 at 6:02:15 AM UTC+2, James Schneider wrote:
>
> Well, the Desk model you provided is blank, but I'll believe you that 
> there's a favorite_or_nearby_chairs attribute. ;-)
>
> Should be relatively simple. Just add a .select_related('nearby_desks') to 
> your existing query and that should pull in the associated Desk object in a 
> single query. You can also substitute in prefetch_related(), although 
> you'll still have two queries at that point.
>
> If you are trying to profile your site, I would recommend the 
> Django-debug-toolbar. That should tell you whether or not that query set is 
> the culprit.
>
> -James
> On Feb 25, 2015 1:28 PM, "Ram Rachum" > 
> wrote:
>
>> Hi James,
>>
>> I've read the docs but I still couldn't figure it out. My queryset works 
>> great in production, I'm trying to optimize it because our pageloads are 
>> too slow. I know how to use querysets in Django pretty well, I just don't 
>> know how to use `Prefetch`. 
>>
>> Can you give me the solution for the simplified example I gave? This 
>> might help me figure out what I'm not understanding. One thing that might 
>> be unclear with the example I gave, is that I meant I want to get a 
>> queryset for `Desk` where every desk has an attribute names 
>> `favorite_or_nearby_chairs` 
>> which contains the queryset of chairs that I desrcibed, prefetched.
>>
>>
>> Thanks,
>> Ram.
>>
>> On Wed, Feb 25, 2015 at 11:18 PM, James Schneider > > wrote:
>>
>>> I assume that you are talking about the select_related() and 
>>> prefetch_related() queryset methods?
>>>
>>>
>>> https://docs.djangoproject.com/en/1.7/ref/models/querysets/#select-related
>>>
>>> https://docs.djangoproject.com/en/1.7/ref/models/querysets/#prefetch-related
>>>
>>> Both of those sections have excellent examples, and detail what the 
>>> differences are (primarily joins vs. separate queries, respectively).
>>>
>>> For better help, you'll need to go into more detail about the queries 
>>> you are trying to make, what you've tried (with code examples if possible), 
>>> and the results/errors you are seeing.
>>>
>>> In general, I would try to get an initial queryset working and gathering 
>>> the correct results first before looking at optimizations such as 
>>> select_related(). Any sort of pre-fetching will only confuse the situation 
>>> if the base queryset is incorrect.
>>>
>>> -James
>>>
>>> On Wed, Feb 25, 2015 at 12:05 PM, cool-RR >> > wrote:
>>>
 Hi guys,

 I'm trying to solve a problem using the new `Prefetch` but I can't 
 figure out how to use it. 

 I have these models:

 class Desk(django.db.models.Model):
 pass
 
 class Chair(django.db.models.Model):
 desk = django.db.models.Foreignkey('Desk', 
 related_name='chair',)
 nearby_desks = django.db.models.ManyToManyField(
 'Desk',
 blank=True,
 )

 I want to get a queryset for `Desk`, but it should also include a 
 prefetched attribute `favorite_or_nearby_chairs`, whose value should be 
 equal to: 

 Chair.objects.filter(
 (django.db.models.Q(nearby_desks=desk) | 
 django.db.models.Q(desk=desk)),
 some_other_lookup=whatever,
 )

 Is this possible with `Prefetch`? I couldn't figure out how to use the 
 arguments.


 Thanks,
 Ram.

 -- 
 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/46d9fdb7-c008-4496-acda-ac7cb30b4a89%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>  -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/

Re: Using Signals - request_finished

2015-02-26 Thread Rodrigo Zayit
put on your __init__.py file:

from signals import request_finished_callback

I guess it'll work.


Atenciosamente,
Rodrigo de Oliveira

On Wed, Feb 25, 2015 at 6:21 PM, Rootz  wrote:

> Still not working
>
>
> On Wednesday, February 25, 2015 at 12:55:29 PM UTC-5, Rodrigo Zayit wrote:
>>
>> If it is being loaded and it is not working, try to do by this way:
>>
>> from django.core.signals import request_finished
>> from django.dispatch import receiver
>>
>> @receiver(request_finished)
>> def request_finished_callback(sender, **kwargs):
>> # . . .
>>
>> On Wednesday, 25 February 2015 14:01:24 UTC-3, Rootz wrote:
>>>
>>> I have tried using the request_finished signal but nothing happens when
>>> I tried testing it.
>>> What suggestions or recommendations can I do to help fix the problem?
>>>
>>> Thank you.
>>>
>>>
>>> Below is a sample of the signals.py file (sample is taken from
>>> djangoproject.com )
>>>
>>> ###SIGNALS.PY
>>>
>>>
>>> from django.core.signals import request_finished
>>>
>>>
>>> def my_callback(sender, **kwargs):
>>> print("request finished")
>>>
>>> request_finished.connect(my_callback)
>>>
>>>
>>>
>>>  --
> 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/e2287639-0b90-4e27-9766-bf4bd356fadd%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/CAL6GM4JJEVbWokRp9LKOJEGG_Mh26eDFHB81UCjW%3DkdatPyFsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to put files in different dirs

2015-02-26 Thread Rodrigo Zayit
Yeah! Or you can write your own method to upload_to. It is easy too.

I've made a simple example:

https://gist.github.com/rodrigo-zayit/604da297d9c30e7d

This example save the pictures in:

media/images/products/1/product-slug/randomstring.ext

Where "1" is the id of the product's category.


Best regards,
Rodrigo Zayit



On Thursday, 26 February 2015 06:18:29 UTC-3, Michael Pöhn wrote:
>
> On 26.02.2015 02:30, 163 email wrote: 
> > yes , what i mean is "media files". 
> > there are so many file,may be several thousands ,to be uploaded 
> > from client to server. 
> > if all files in one dir , it'll be slow. 
> > but i don't find any way  put files in different dirs just using django. 
> > now i write a function to put  files in different dirs ,but it complex. 
> > is there any easy way ? 
> > Thanks ! 
> >  
> > 163 email 
>
> There is an easy way for accomplishing what you want mentioned in 
> djangos docs: 
>
> »For example, say your MEDIA_ROOT is set to '/home/media', and upload_to 
> is set to 'photos/%Y/%m/%d'. The '%Y/%m/%d' part of upload_to is 
> strftime() formatting; '%Y' is the four-digit year, '%m' is the 
> two-digit month and '%d' is the two-digit day. If you upload a file on 
> Jan. 15, 2007, it will be saved in the directory 
> /home/media/photos/2007/01/15.« 
>
>
> https://docs.djangoproject.com/en/1.7/ref/models/fields/#django.db.models.FileField.storage
>  
>
>

-- 
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/0d872736-383a-4975-bb46-ed3fb888b946%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can the new `Prefetch` solve my problem?

2015-02-26 Thread aRkadeFR

I may not have completely understand your problem, but
why not prefetching all the chairs? and then with the (new)
attribute favorite_or_nearby_chairs loading only the favorite
or nearby one?

like:
@property
def favorite_or_nearby_chairs(self):
for chair in self.chair_set.all():
  #filter...
  ans += ...
return ans

It will only hit the DB once thanks to the first join of desk
<-> chair.

On 02/26/2015 11:28 AM, cool-RR wrote:

James, you misunderstood me.

There isn't supposed to be a `favorite_or_nearby_chairs` attribute. 
That's the new attribute I want the prefetching to add to the `Desk` 
queryset that I need. Also, I don't understand why you'd tell me to 
add a `.select_related('nearby_desks')` to my query. Are you talking 
about the query that starts with `Chair.objects`? I'm not looking to 
get a `Chair` queryset. I'm looking to get a `Desk` queryset, which 
has a prefetched attribute `favorite_or_nearby_chairs` which contains 
the `Chair` queryset I wrote down.



Thanks,
Ram.

On Thursday, February 26, 2015 at 6:02:15 AM UTC+2, James Schneider 
wrote:


Well, the Desk model you provided is blank, but I'll believe you
that there's a favorite_or_nearby_chairs attribute. ;-)

Should be relatively simple. Just add a
.select_related('nearby_desks') to your existing query and that
should pull in the associated Desk object in a single query. You
can also substitute in prefetch_related(), although you'll still
have two queries at that point.

If you are trying to profile your site, I would recommend the
Django-debug-toolbar. That should tell you whether or not that
query set is the culprit.

-James

On Feb 25, 2015 1:28 PM, "Ram Rachum" > wrote:

Hi James,

I've read the docs but I still couldn't figure it out. My
queryset works great in production, I'm trying to optimize it
because our pageloads are too slow. I know how to use
querysets in Django pretty well, I just don't know how to use
`Prefetch`.

Can you give me the solution for the simplified example I
gave? This might help me figure out what I'm not
understanding. One thing that might be unclear with the
example I gave, is that I meant I want to get a queryset for
`Desk` where every desk has an attribute names
`favorite_or_nearby_chairs` which contains the queryset of
chairs that I desrcibed, prefetched.


Thanks,
Ram.

On Wed, Feb 25, 2015 at 11:18 PM, James Schneider
> wrote:

I assume that you are talking about the select_related()
and prefetch_related() queryset methods?


https://docs.djangoproject.com/en/1.7/ref/models/querysets/#select-related



https://docs.djangoproject.com/en/1.7/ref/models/querysets/#prefetch-related



Both of those sections have excellent examples, and detail
what the differences are (primarily joins vs. separate
queries, respectively).

For better help, you'll need to go into more detail about
the queries you are trying to make, what you've tried
(with code examples if possible), and the results/errors
you are seeing.

In general, I would try to get an initial queryset working
and gathering the correct results first before looking at
optimizations such as select_related(). Any sort of
pre-fetching will only confuse the situation if the base
queryset is incorrect.

-James

On Wed, Feb 25, 2015 at 12:05 PM, cool-RR
> wrote:

Hi guys,

I'm trying to solve a problem using the new `Prefetch`
but I can't figure out how to use it.

I have these models:

class Desk(django.db.models.Model):
pass
class Chair(django.db.models.Model):
desk = django.db.models.Foreignkey('Desk',
related_name='chair',)
nearby_desks = django.db.models.ManyToManyField(
'Desk',
blank=True,
)

I want to get a queryset for `Desk`, but it should
also include a prefetched attribute
`favorite_or_nearby_chairs`, whose value should be
equal to:

Chair.objects.filter(
(django.db.models.Q(nearby_desks=desk) |
django.db.models.Q(desk=desk)),
some_other_lookup=whatever,
)

Is this possible with `Prefetch`? I couldn't figure
 

Re: Can the new `Prefetch` solve my problem?

2015-02-26 Thread Ram Rachum
There may be a big number of chairs, and I don't want all the chairs
prefetched. I want to have the database filter them according to the
queryset I specified in a single call, I don't want to filter them in
Python or make a new call to filter them.

Thanks,
Ram.

On Thu, Feb 26, 2015 at 1:48 PM, aRkadeFR  wrote:

>  I may not have completely understand your problem, but
> why not prefetching all the chairs? and then with the (new)
> attribute favorite_or_nearby_chairs loading only the favorite
> or nearby one?
>
> like:
> @property
> def favorite_or_nearby_chairs(self):
> for chair in self.chair_set.all():
>   #filter...
>   ans += ...
> return ans
>
> It will only hit the DB once thanks to the first join of desk
> <-> chair.
>
>
> On 02/26/2015 11:28 AM, cool-RR wrote:
>
> James, you misunderstood me.
>
>  There isn't supposed to be a `favorite_or_nearby_chairs` attribute.
> That's the new attribute I want the prefetching to add to the `Desk`
> queryset that I need. Also, I don't understand why you'd tell me to add a `
> .select_related('nearby_desks')` to my query. Are you talking about the
> query that starts with `Chair.objects`? I'm not looking to get a `Chair`
> queryset. I'm looking to get a `Desk` queryset, which has a prefetched
> attribute `favorite_or_nearby_chairs` which contains the `Chair` queryset
> I wrote down.
>
>
>  Thanks,
> Ram.
>
> On Thursday, February 26, 2015 at 6:02:15 AM UTC+2, James Schneider wrote:
>>
>> Well, the Desk model you provided is blank, but I'll believe you that
>> there's a favorite_or_nearby_chairs attribute. ;-)
>>
>> Should be relatively simple. Just add a .select_related('nearby_desks')
>> to your existing query and that should pull in the associated Desk object
>> in a single query. You can also substitute in prefetch_related(), although
>> you'll still have two queries at that point.
>>
>> If you are trying to profile your site, I would recommend the
>> Django-debug-toolbar. That should tell you whether or not that query set is
>> the culprit.
>>
>> -James
>> On Feb 25, 2015 1:28 PM, "Ram Rachum"  wrote:
>>
>>> Hi James,
>>>
>>>  I've read the docs but I still couldn't figure it out. My queryset
>>> works great in production, I'm trying to optimize it because our pageloads
>>> are too slow. I know how to use querysets in Django pretty well, I just
>>> don't know how to use `Prefetch`.
>>>
>>>  Can you give me the solution for the simplified example I gave? This
>>> might help me figure out what I'm not understanding. One thing that might
>>> be unclear with the example I gave, is that I meant I want to get a
>>> queryset for `Desk` where every desk has an attribute names 
>>> `favorite_or_nearby_chairs`
>>> which contains the queryset of chairs that I desrcibed, prefetched.
>>>
>>>
>>>  Thanks,
>>> Ram.
>>>
>>> On Wed, Feb 25, 2015 at 11:18 PM, James Schneider 
>>> wrote:
>>>
  I assume that you are talking about the select_related() and
 prefetch_related() queryset methods?

  https://docs.djangoproject.com/en/1.7/ref/models/
 querysets/#select-related
 https://docs.djangoproject.com/en/1.7/ref/models/
 querysets/#prefetch-related

  Both of those sections have excellent examples, and detail what the
 differences are (primarily joins vs. separate queries, respectively).

  For better help, you'll need to go into more detail about the queries
 you are trying to make, what you've tried (with code examples if possible),
 and the results/errors you are seeing.

  In general, I would try to get an initial queryset working and
 gathering the correct results first before looking at optimizations such as
 select_related(). Any sort of pre-fetching will only confuse the situation
 if the base queryset is incorrect.

  -James

 On Wed, Feb 25, 2015 at 12:05 PM, cool-RR  wrote:

> Hi guys,
>
>  I'm trying to solve a problem using the new `Prefetch` but I can't
> figure out how to use it.
>
>  I have these models:
>
>   class Desk(django.db.models.Model):
> pass
>
> class Chair(django.db.models.Model):
> desk = django.db.models.Foreignkey('Desk',
> related_name='chair',)
> nearby_desks = django.db.models.ManyToManyField(
> 'Desk',
> blank=True,
> )
>
>  I want to get a queryset for `Desk`, but it should also include a
> prefetched attribute `favorite_or_nearby_chairs`, whose value should be
> equal to:
>
>  Chair.objects.filter(
> (django.db.models.Q(nearby_desks=desk) |
> django.db.models.Q(desk=desk)),
> some_other_lookup=whatever,
> )
>
>  Is this possible with `Prefetch`? I couldn't figure out how to use
> the arguments.
>
>
>  Thanks,
> Ram.
>  --
> You received this message because you are subscribed to the Google

Re: Can the new `Prefetch` solve my problem?

2015-02-26 Thread aRkadeFR

got it, so you want to prefetch but not all chairs.

I will def follow this thread to see the possibilities of Prefetch :)

On 02/26/2015 12:52 PM, Ram Rachum wrote:
There may be a big number of chairs, and I don't want all the chairs 
prefetched. I want to have the database filter them according to the 
queryset I specified in a single call, I don't want to filter them in 
Python or make a new call to filter them.


Thanks,
Ram.

On Thu, Feb 26, 2015 at 1:48 PM, aRkadeFR > wrote:


I may not have completely understand your problem, but
why not prefetching all the chairs? and then with the (new)
attribute favorite_or_nearby_chairs loading only the favorite
or nearby one?

like:
@property
def favorite_or_nearby_chairs(self):
for chair in self.chair_set.all():
  #filter...
  ans += ...
return ans

It will only hit the DB once thanks to the first join of desk
<-> chair.


On 02/26/2015 11:28 AM, cool-RR wrote:

James, you misunderstood me.

There isn't supposed to be a `favorite_or_nearby_chairs`
attribute. That's the new attribute I want the prefetching to add
to the `Desk` queryset that I need. Also, I don't understand why
you'd tell me to add a `.select_related('nearby_desks')` to my
query. Are you talking about the query that starts with
`Chair.objects`? I'm not looking to get a `Chair` queryset. I'm
looking to get a `Desk` queryset, which has a prefetched
attribute `favorite_or_nearby_chairs` which contains the `Chair`
queryset I wrote down.


Thanks,
Ram.

On Thursday, February 26, 2015 at 6:02:15 AM UTC+2, James
Schneider wrote:

Well, the Desk model you provided is blank, but I'll believe
you that there's a favorite_or_nearby_chairs attribute. ;-)

Should be relatively simple. Just add a
.select_related('nearby_desks') to your existing query and
that should pull in the associated Desk object in a single
query. You can also substitute in prefetch_related(),
although you'll still have two queries at that point.

If you are trying to profile your site, I would recommend the
Django-debug-toolbar. That should tell you whether or not
that query set is the culprit.

-James

On Feb 25, 2015 1:28 PM, "Ram Rachum"  wrote:

Hi James,

I've read the docs but I still couldn't figure it out. My
queryset works great in production, I'm trying to
optimize it because our pageloads are too slow. I know
how to use querysets in Django pretty well, I just don't
know how to use `Prefetch`.

Can you give me the solution for the simplified example I
gave? This might help me figure out what I'm not
understanding. One thing that might be unclear with the
example I gave, is that I meant I want to get a queryset
for `Desk` where every desk has an attribute names
`favorite_or_nearby_chairs` which contains the queryset
of chairs that I desrcibed, prefetched.


Thanks,
Ram.

On Wed, Feb 25, 2015 at 11:18 PM, James Schneider
 wrote:

I assume that you are talking about the
select_related() and prefetch_related() queryset methods?


https://docs.djangoproject.com/en/1.7/ref/models/querysets/#select-related

https://docs.djangoproject.com/en/1.7/ref/models/querysets/#prefetch-related

Both of those sections have excellent examples, and
detail what the differences are (primarily joins vs.
separate queries, respectively).

For better help, you'll need to go into more detail
about the queries you are trying to make, what you've
tried (with code examples if possible), and the
results/errors you are seeing.

In general, I would try to get an initial queryset
working and gathering the correct results first
before looking at optimizations such as
select_related(). Any sort of pre-fetching will only
confuse the situation if the base queryset is incorrect.

-James

On Wed, Feb 25, 2015 at 12:05 PM, cool-RR
 wrote:

Hi guys,

I'm trying to solve a problem using the new
`Prefetch` but I can't figure out how to use it.

I have these models:

class Desk(django.db.models.Model):
pass
class Chair(django.db.models.Model):
desk =
django.db.models.Foreignkey('Desk',
related_name=

Chained foreign Key

2015-02-26 Thread Arumuga Odhuvar Sekkizhar
Good Morning,

  Can I get the code or methode in Python
Django to how to use Chained foreign Key? That is After I select a State of
a Country, in adjacent scroll down box should display *only* the respective
district of that state. Not all the district in the country.

Please let me get a solution for the above problem

by
Sekkizhar

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


Django suppotted host

2015-02-26 Thread Harish Pentapalli
Hello guys,

I  am new to django community. I am creating a website in django,html5. I 
would like to know the best and cheapest domain hosts for my website, with 
the best support and to django.  

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/1527a852-22bb-46a1-bec0-68c5442a3776%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Getting problem with installation in Django

2015-02-26 Thread abhishek jain


Dear Sir/ Madam,

  Myself Abhishek want to work on Python framework to develop a web page 
in python as a fresher, so i have downloaded the python 3.4 and follow 
the steps from quick install guide as

1- Install Pyhton ( which was verified by click on IDLE (Python 3.4 GUI 
- 32 bit))
2- Setup a database ( using MS Access)
3- Install Django
   a- pip
   b- setuptools-12.2
   c- django-django-1.7a2-3046-g65441bb

run all the setup.py files of each. and i have saved these files in c: \ 
Python34  folder.

Then verified by the following command in python command line


import django

but we get an error as


  >>> import django
Traceback (most recent call last):
   File "", line 1, in 
 import django
ImportError: No module named 'django'


  I request you to kindly provide me proper guide lines to install the 
Djnago in my system with proper steps , so that i can start to develop 
the web page.



Thanks And Regards,

Abhishek


-- 
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/78a84929-1ae7-4c83-8ac0-8232ce1728fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Research: Translations od documentation

2015-02-26 Thread Tim Graham
Maybe you aren't aware of the existing opportunity to translate Django's 
documentation?

https://docs.djangoproject.com/en/dev/internals/contributing/localizing/#documentation

On Thursday, February 26, 2015 at 5:11:21 AM UTC-5, Tomáš Ehrlich wrote:
>
> Hello, 
> tonight is regular python/ruby meetup in Brno (Czech republic) about 
> documentation. Last few months I’ve been working on project concerning 
> localization of documents. I would like to know your opinion about 
> localization of documentation: 
>
> Do you think it would be useful to translate documentation of: 
> 1) Django 
> 2) Python 
> 3) Any project documented using Sphinx (like numpy, scipy, request, …) 
>
> Three simple answers Yes/No would help me a lot. If you write a short 
> paragraph about your opinion, I will very appreciate it. 
>
> Thank you 
>
>
> Cheers, 
>Tom 
>
>
>

-- 
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/7a8fd44b-5d1c-4c6b-be2b-c60c8c73b596%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Chained foreign Key

2015-02-26 Thread Jorge Andrés Vergara Ebratt
Hey, there is a python package you can install in Django called
django-smart-selects its documentation is pretty easy to follow

On Thu, Feb 26, 2015 at 7:23 AM Arumuga Odhuvar Sekkizhar <
vaariyar2...@gmail.com> wrote:

> Good Morning,
>
>   Can I get the code or methode in Python
> Django to how to use Chained foreign Key? That is After I select a State of
> a Country, in adjacent scroll down box should display *only* the
> respective district of that state. Not all the district in the country.
>
> Please let me get a solution for the above problem
>
> by
> Sekkizhar
>
> --
> 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/CAE3eSFV02CjX1oii%3DFE4-EX4S9cMpWWo7fo4eHmV4ojXJw6v8A%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/CAAeX05G%2BYzESjYKD23qyNaEZDaOiSdfhfHi1ECFxB%3DL9oNfS8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: MySQLdb Missing Module errors

2015-02-26 Thread Tim Graham
You're using an incorrect package name for MySQLdb. It should be: pip 
install MySQL-python
However, we currently recommend using mysqlclient as it's actively 
maintained.

The officially supported MySQL drivers are documented here:
https://docs.djangoproject.com/en/stable/ref/databases/#mysql-db-api-drivers

On Wednesday, February 25, 2015 at 6:07:47 PM UTC-5, Rootz wrote:
>
> I recently installed the django framework ( v1.7.4 ) and the mysql 
> database connector ( pymysql ) for python. It is my understanding that the 
> MySQLdb python connector is depreciated and is no longer available for 
> download through PIP . However I installed pymysql which is an alternate 
> download for MySQLdb connector for python. The connector (pysql) works with 
> the MySQL database installed but my current django installation does not 
> work because I recieve errors about missing MySQLdb module.
>
> However despite the setback trying to use the MySQLdb package I was able 
> to make changes to the installed django package ( 
> django/db/backends/mysql/base.py ) that
> help to make my django projects functional and error free now. 
>
> I hope this will help those in the Django community, whom are affected by 
> the same errors that I was recieving.
>
> Thanks
>
> Below I have outlined some of the changes I made to my django package are 
> as follows:
>
> Updates made in base.py (The base.py is locate in the django package)
> Path to base.py inside the django package ( django/db/backends/mysql/ )
> import pymysql as Database#MySQLdb as Database
>
>
>
> from pymysql.converters import conversions, Thing2Literal
> from pymysql.constants import FIELD_TYPE, CLIENT
>
>
> ### line 30 - 31 replaced MySQLdb for pymysql
> ### line 15 replaced MySQLdb for pymysql
>
>
> #from MySQLdb.converters import conversions, Thing2Literal
> #from MySQLdb.constants import FIELD_TYPE, CLIENT
>
>
>
>
> Below is a snippet installing MySQLdb connector using PIP
>
> C:\Users\root\Documents\GitHub\djangoproject-tutorial\tutorial> pip 
> install mysqldb
> Downloading/unpacking mySQLdb
>   Could not find any downloads that satisfy the requirement mySQLdb
> Cleaning up...
> No distributions at all found for mySQLdb
> Storing debug log for failure in C:\Users\root\pip\pip.log
> C:\Users\root\Documents\GitHub\djangoproject-tutorial\tutorial>
>
>
> Below is a snippet of the Django-1.7.4 interacting with the pymysql 
> connector
>
> File 
> "C:\Users\root\Documents\GitHub\djangoproject-tutorial\tutorial\lib\site-packages\django\db\backends\mysql\base.py"
> , line 18, in 
> raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: 
> No module named 'MySQLdb'
>
>
>

-- 
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/1f5fe20c-b2b0-4dce-9761-abcab4d3821c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrations force me to have, forever, any name/reference I use in field validators=, choices=, whatever, valid forever (even if the requirements change).

2015-02-26 Thread Tim Graham
Yes, it's expected behavior. Please see the documentation on the topic:
https://docs.djangoproject.com/en/stable/topics/migrations/#historical-models

On Wednesday, February 25, 2015 at 3:25:19 PM UTC-5, Luis Masuelli wrote:
>
> I have an issue with migrations.
>
> Suppose I declare (in my application, with name myapp) a field with a 
> validators= declared. In such value (which is an iterable), I declare a 
> function:
>
> class MyModel(models.Model):
> """
> This one is identifiable.
> """
>
> identifier = models.CharField(max_length=10, unique=True, validators=[
> valid_identifier])
>
> Assume I created the migration with makemigrations:
>
> # -*- coding: utf-8 -*-
> from __future__ import unicode_literals
>
> from django.db import models, migrations
> from django.conf import settings
> import django.core.validators
> import micnt.models
>
>
> class Migration(migrations.Migration):
>
> dependencies = [
> ...
> ]
>
> operations = [
> migrations.CreateModel(
> name='MyModel',
> fields=[
> ('identifier', models.CharField(max_length=10, unique=True
> , validators=[myapp.models.valid_identifier])),
> ],
> options={
> },
> bases=(models.Model,),
> ),
> ]
>
> Assume valid_identifier is any external callable which will take one 
> positional argument, and eventually raise ValidationError under certain 
> conditions.
>
> Now the requirements vary: The identifier may be national or foreign, so 
> the country is required as an additional field, and also a discriminator 
> field. Additionally, the validation I must perform is cross-field, so 
> instead of using something in validators, I define a clean() method, and 
> make the combination of country/identifier unique, instead of just the 
> identifier unique:
>
> class MyModel(models.Model):
> """
> This one is identifiable.
> """
>
> identifier_type = models.CharField(max_length=10, 
> choices=(('passport', _(u'Passport')), ('national', _(u'National'))), 
> null=False)
> identifier = models.CharField(max_length=10)
> country = models.ForeignKey(Country, null=False)  # assume Country 
> model exists
>
> class Meta:
> unique_together = (('identifier', 'country'),)
>
> def clean(self):
> raise ValidationError('Implement this!')
> 
>
> And then, I don't need anymore the valid_identifier function, since my 
> code does not use it anymore. So I delete it.
>
> Now I will create the migration with makemigrations as usual. What will 
> happen?
>
> a. The command will succeed.
> b. The command will explode (i. e. a normal Python exception).
> c. The command will create an inconsistent migration, without exploding.
> d. Jesus will come again.
> e. The command will get into a kind of endless loop.
>
> If you guesses "b", you were right. Django will report an error, since 
> myapp.models.valid_identifier does not exist anymore (AttributeError).
>
> So, once I set a value for validators= parameter and create a migration, I 
> am forced to keep such reference valid for the rest of my life (e.g. by 
> having valid_identifier=None, if I don't need the function anymore), or 
> else the migrations will not work again since they will be traversed, 
> imported, and will get such AttributeError.
>
> Is this an expected, normal, behavior?
>

-- 
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/aa3cc60a-50e2-4be6-a430-0ae1d351e2b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Best django domain host for signup page

2015-02-26 Thread Harish Pentapalli
Hello guys,

I  am new to django community. I am creating a website in django,html5. I 
would like to know the best and cheapest domain hosts for my website, with 
the best support and to django.  

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/feb8446b-9fa7-4332-a3bd-b2ee39088d4a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best django domain host for signup page

2015-02-26 Thread Rodrigo Zayit
If you know how to setup a server, I recommend DigitalOcean
 - They have tutorials
to help you to setup the server.


Cheers,
Rodrigo




Atenciosamente,
Rodrigo de Oliveira

On Thu, Feb 26, 2015 at 10:25 AM, Harish Pentapalli 
wrote:

> Hello guys,
>
> I  am new to django community. I am creating a website in django,html5. I
> would like to know the best and cheapest domain hosts for my website, with
> the best support and to django.
>
> 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/feb8446b-9fa7-4332-a3bd-b2ee39088d4a%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/CAL6GM4J11NFUjNmTrDcnSU2vG%3DQq%3D%3DjuW_5SeneSXghg-jBrCg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Research: Translations od documentation

2015-02-26 Thread Tomáš Ehrlich
Hi Tim,
I'm aware that it's possible to translate Django documentation. I also know 
that it's translated to french only.

My question is one step behind: Does it makes sense to translate Django 
documentation and (more important) keep it updated? Would anyone use it? Is 
English language the common tongue for programmers? Why is Django docs 
translated to one language only? There isn't enough translators or users 
just don't find it useful?

I asked the same question in Czech django user group and most of them 
agreed that it doesn't make sense to translate whole Django documentation. 
It would make sense to translate materials for beginners, like tutorials, 
django book, etc.


So, at the moment, I don't care about the *tool* or *process*. I'm trying 
to figure it out if there is some kind of motivation to do this stuff.

Cheers,
   Tom

Dne čtvrtek 26. února 2015 13:25:38 UTC+1 Tim Graham napsal(a):
>
> Maybe you aren't aware of the existing opportunity to translate Django's 
> documentation?
>
>
> https://docs.djangoproject.com/en/dev/internals/contributing/localizing/#documentation
>
> On Thursday, February 26, 2015 at 5:11:21 AM UTC-5, Tomáš Ehrlich wrote:
>>
>> Hello, 
>> tonight is regular python/ruby meetup in Brno (Czech republic) about 
>> documentation. Last few months I’ve been working on project concerning 
>> localization of documents. I would like to know your opinion about 
>> localization of documentation: 
>>
>> Do you think it would be useful to translate documentation of: 
>> 1) Django 
>> 2) Python 
>> 3) Any project documented using Sphinx (like numpy, scipy, request, …) 
>>
>> Three simple answers Yes/No would help me a lot. If you write a short 
>> paragraph about your opinion, I will very appreciate it. 
>>
>> Thank you 
>>
>>
>> Cheers, 
>>Tom 
>>
>>
>>

-- 
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/c81d59cb-f348-4bfc-85e9-2bfe0f273d09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrations force me to have, forever, any name/reference I use in field validators=, choices=, whatever, valid forever (even if the requirements change).

2015-02-26 Thread Carl Meyer
On 02/26/2015 08:41 AM, Carsten Fuchs wrote:
> Hi all,
> 
> Am 26.02.2015 um 13:54 schrieb Tim Graham:
>> Yes, it's expected behavior. Please see the documentation on the topic:
>> https://docs.djangoproject.com/en/stable/topics/migrations/#historical-models
>>
> 
> I have not yet tried this, but won't squashing migrations as a side
> effect also get us rid of dependencies of historical models?

Yes, squashmigrations is the right way to deal with this problem.

If you have RunPython/RunSQL migrations that can also safely go away,
you'll need to manually excise them before squashing in order to get a
complete squash, since they are opaque to squashmigrations and won't be
optimized across. See https://code.djangoproject.com/ticket/24109

Carl

-- 
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/54EF40B4.6020305%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Migrations force me to have, forever, any name/reference I use in field validators=, choices=, whatever, valid forever (even if the requirements change).

2015-02-26 Thread Carsten Fuchs

Hi all,

Am 26.02.2015 um 13:54 schrieb Tim Graham:

Yes, it's expected behavior. Please see the documentation on the topic:
https://docs.djangoproject.com/en/stable/topics/migrations/#historical-models


I have not yet tried this, but won't squashing migrations as a side 
effect also get us rid of dependencies of historical models?


Best regards,
Carsten

--
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/54EF3EAE.3040004%40cafu.de.
For more options, visit https://groups.google.com/d/optout.


Re: Using Signals - request_finished

2015-02-26 Thread Rootz
thanks it worked

On Thursday, February 26, 2015 at 5:54:02 AM UTC-5, Rodrigo Zayit wrote:
>
> put on your __init__.py file:
>
> from signals import request_finished_callback
>
> I guess it'll work.
>
>
> Atenciosamente,
> Rodrigo de Oliveira
>
> On Wed, Feb 25, 2015 at 6:21 PM, Rootz > 
> wrote:
>
>> Still not working
>>
>>
>> On Wednesday, February 25, 2015 at 12:55:29 PM UTC-5, Rodrigo Zayit wrote:
>>>
>>> If it is being loaded and it is not working, try to do by this way:
>>>
>>> from django.core.signals import request_finished
>>> from django.dispatch import receiver
>>>
>>> @receiver(request_finished)
>>> def request_finished_callback(sender, **kwargs):
>>> # . . .
>>>
>>> On Wednesday, 25 February 2015 14:01:24 UTC-3, Rootz wrote:

 I have tried using the request_finished signal but nothing happens when 
 I tried testing it.
 What suggestions or recommendations can I do to help fix the problem?

 Thank you.


 Below is a sample of the signals.py file (sample is taken from 
 djangoproject.com )

 ###SIGNALS.PY


 from django.core.signals import request_finished


 def my_callback(sender, **kwargs):
 print("request finished")
 
 request_finished.connect(my_callback)



  -- 
>> 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/e2287639-0b90-4e27-9766-bf4bd356fadd%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/5ed079f0-581c-4464-ac09-768e01500523%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Model field with default value and choices is always reported as changed, even if unchanged

2015-02-26 Thread Carsten Fuchs

Hi,

Am 25.02.2015 um 19:11 schrieb Carsten Fuchs:

the parent model's History view claims that field "monat" of TestModel has been 
changed,


I got at least a little bit further: This is easily reproducible in a 
minimal project/app test case with SQLite exactly as described in 
Django's intro tutorial 01. This is the entire contents of my test app's 
`models.py` file:



# -*- coding: utf-8 -*-
from django.db import models

def VormonatsMonat():
return 1

MONTHS_CHOICES = (
(1, "Jan"),
(2, "Feb"),
)

class Choice(models.Model):
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
monat = models.IntegerField(default=VormonatsMonat, 
choices=MONTHS_CHOICES)



Then, at the `./manage.py shell` prompt (creating a Choice instance is 
omitted here):


>>> from django.forms import ModelForm
>>> from TestApp.models import Choice
>>> class ChoiceForm(ModelForm):
... class Meta:
... model = Choice
... fields = ["choice_text", "votes", "monat"]
...
>>> ch =  Choice.objects.get(pk=1)
>>> chv = Choice.objects.values().get(pk=1)
>>> ch

>>> chv
{'monat': 1, 'choice_text': u'just a test', 'votes': 0, u'id': 1}
>>> ChoiceForm(chv, initial=chv, instance=ch).has_changed()
True


The expected output is `False`, which is (in a new shell session) in 
fact obtained whenever the definition of field `monat` is slightly 
changed, e.g. to a constant default value rather than a callable, or 
with no choices.


Any thoughts please?

Best regards,
Carsten

--
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/54EF60B7.1010204%40cafu.de.
For more options, visit https://groups.google.com/d/optout.


Re: Can the new `Prefetch` solve my problem?

2015-02-26 Thread James Schneider
Yep, looks like I misunderstood.

So, you want to have something like this pseudo code:

desks = Desk.objects.filter()
for desk in desks:
print desk.favorite_or_nearby_chairs

And have favorite_or_nearby_chairs be pre-populated with your Chair
queryset mentioned earlier?

Due to the nature of the custom Chair queryset, I doubt you can do any sort
of pre-fetching that would reduce the number of queries. You can probably
simulate the effect of prefetch_related() though by overriding the
__init__() method of your Desk model, and having the Desk model
populate favorite_or_nearby_chairs whenever a Desk object is created.

class Desk(models.Model)
def __init__(self):
# using list() to force the queryset to be evaluated
self.favorite_or_nearby_chairs = list()


However, that probably doesn't buy you much since you are still doing an
extra query for every Desk you pull from your original query.

Funny enough, I was googling around for an answer here, and stumbled across
this:




On Thu, Feb 26, 2015 at 4:19 AM, aRkadeFR  wrote:

>  got it, so you want to prefetch but not all chairs.
>
> I will def follow this thread to see the possibilities of Prefetch :)
>
>
> On 02/26/2015 12:52 PM, Ram Rachum wrote:
>
> There may be a big number of chairs, and I don't want all the chairs
> prefetched. I want to have the database filter them according to the
> queryset I specified in a single call, I don't want to filter them in
> Python or make a new call to filter them.
>
>  Thanks,
> Ram.
>
> On Thu, Feb 26, 2015 at 1:48 PM, aRkadeFR  wrote:
>
>>  I may not have completely understand your problem, but
>> why not prefetching all the chairs? and then with the (new)
>> attribute favorite_or_nearby_chairs loading only the favorite
>> or nearby one?
>>
>> like:
>> @property
>> def favorite_or_nearby_chairs(self):
>> for chair in self.chair_set.all():
>>   #filter...
>>   ans += ...
>> return ans
>>
>> It will only hit the DB once thanks to the first join of desk
>> <-> chair.
>>
>>
>> On 02/26/2015 11:28 AM, cool-RR wrote:
>>
>>  James, you misunderstood me.
>>
>>  There isn't supposed to be a `favorite_or_nearby_chairs` attribute.
>> That's the new attribute I want the prefetching to add to the `Desk`
>> queryset that I need. Also, I don't understand why you'd tell me to add a `
>> .select_related('nearby_desks')` to my query. Are you talking about the
>> query that starts with `Chair.objects`? I'm not looking to get a `Chair`
>> queryset. I'm looking to get a `Desk` queryset, which has a prefetched
>> attribute `favorite_or_nearby_chairs` which contains the `Chair`
>> queryset I wrote down.
>>
>>
>>  Thanks,
>> Ram.
>>
>> On Thursday, February 26, 2015 at 6:02:15 AM UTC+2, James Schneider
>> wrote:
>>>
>>> Well, the Desk model you provided is blank, but I'll believe you that
>>> there's a favorite_or_nearby_chairs attribute. ;-)
>>>
>>> Should be relatively simple. Just add a .select_related('nearby_desks')
>>> to your existing query and that should pull in the associated Desk object
>>> in a single query. You can also substitute in prefetch_related(), although
>>> you'll still have two queries at that point.
>>>
>>> If you are trying to profile your site, I would recommend the
>>> Django-debug-toolbar. That should tell you whether or not that query set is
>>> the culprit.
>>>
>>> -James
>>> On Feb 25, 2015 1:28 PM, "Ram Rachum"  wrote:
>>>
 Hi James,

  I've read the docs but I still couldn't figure it out. My queryset
 works great in production, I'm trying to optimize it because our pageloads
 are too slow. I know how to use querysets in Django pretty well, I just
 don't know how to use `Prefetch`.

  Can you give me the solution for the simplified example I gave? This
 might help me figure out what I'm not understanding. One thing that might
 be unclear with the example I gave, is that I meant I want to get a
 queryset for `Desk` where every desk has an attribute names 
 `favorite_or_nearby_chairs`
 which contains the queryset of chairs that I desrcibed, prefetched.


  Thanks,
 Ram.

 On Wed, Feb 25, 2015 at 11:18 PM, James Schneider 
 wrote:

>  I assume that you are talking about the select_related() and
> prefetch_related() queryset methods?
>
>
> https://docs.djangoproject.com/en/1.7/ref/models/querysets/#select-related
>
> https://docs.djangoproject.com/en/1.7/ref/models/querysets/#prefetch-related
>
>  Both of those sections have excellent examples, and detail what the
> differences are (primarily joins vs. separate queries, respectively).
>
>  For better help, you'll need to go into more detail about the
> queries you are trying to make, what you've tried (with code examples if
> possible), and the results/errors you are seeing.
>
>  In general, I would try to get an initial queryset working and
> gathering the correct r

Re: Can the new `Prefetch` solve my problem?

2015-02-26 Thread James Schneider
Whoops, accidentally sent that last one too early, here's the continuation:

However, that probably doesn't buy you much since you are still doing an
extra query for every Desk you pull from your original query.

Funny enough, I was googling around for an answer here, and stumbled across
this:

https://docs.djangoproject.com/en/1.7/ref/models/queries/#django.db.models.Prefetch

which I think is what you were referring to initially in your OP. I wasn't
even aware of its existence. Prefetch() is a helper class for
prefetch_related(). Taking a quick glance through the source code, I would
imagine that it probably won't help you much, since the functionality of
that class only controls the action of prefetch_related().


Zooming out a bit, the crux of your problem is this: An attribute you wish
to populate is not an FK or M2M field, it is an entirely separate Queryset
with some moderately complex filters. The built-in ORM functionality for
pre-loading via prefetch/select_related() is expecting a FK or M2M
relationship and can't  use another queryset AFAIK. The high-level
functionality of prefetch_related() is probably close to what you want,
which is to run a single second query to collect all of
the favorite_or_nearby_chairs for all of the Desks in your original query,
and then glue everything together behind the scenes in Python to make the
desk_obj.favorite_or_nearby_chairs available seamlessly.

I would then wonder if there is another way to organize this data to make
it easier to work with? How about adding a 'favorite_chairs' field to the
Desk model that has an M2M to Chair? I would also update your
'nearby_desks' model field to use 'nearby_chairs' as the related_field.

Then you could do something like the following:

desks = Desk.objects.filter().select_related('nearby_chairs',
'favorite_chairs')

Then, you can modify your model with a property that will return the
concatenation of nearby_chairs and favorite_chairs:

class Desk(models.Model):
@property
def favorite_or_nearby_chairs(self):
return self.nearby_chairs.all() + self.favorite_chairs

I don't believe this will spawn another query, since select_related() will
have already run and have the results cached. You may also want to consider
moving 'nearby_desks' out of Chair and renaming it to 'nearby_chairs' in
Desk, and using a related_name of 'nearby_desks' instead. Then you can
remove the .all() from the property definition from above and it definitely
won't spawn a query. Obviously you'll need to create other processes that
will populate desk.favorite_chairs, which may or may not be feasible.

TL;DR; I don't believe you can pre-fetch anything because of the extra SQL
logic needed to calculate the favorite_or_nearby_chairs attribute. It might
be possible via raw SQL though. Reformatting your data models may lead to
an easier time since you can then take advantage of the some of the
optimizations Django offers.

I'm slightly out in right field on this one, so YMMV, but taking a hard
look at the current model design would be where I would start to try and
eliminate the need for that custom queryset.

Again, the django-debug-toolbar is your friend in these cases, but
obviously a high number of even relatively fast queries can have a
detrimental effect on your load times. Also ensure that the fields you are
using to filter contain indexes, if appropriate/available.

-James




On Thu, Feb 26, 2015 at 10:17 AM, James Schneider 
wrote:

> Yep, looks like I misunderstood.
>
> So, you want to have something like this pseudo code:
>
> desks = Desk.objects.filter()
> for desk in desks:
> print desk.favorite_or_nearby_chairs
>
> And have favorite_or_nearby_chairs be pre-populated with your Chair
> queryset mentioned earlier?
>
> Due to the nature of the custom Chair queryset, I doubt you can do any
> sort of pre-fetching that would reduce the number of queries. You can
> probably simulate the effect of prefetch_related() though by overriding the
> __init__() method of your Desk model, and having the Desk model
> populate favorite_or_nearby_chairs whenever a Desk object is created.
>
> class Desk(models.Model)
> def __init__(self):
> # using list() to force the queryset to be evaluated
> self.favorite_or_nearby_chairs = list()
>
>
> However, that probably doesn't buy you much since you are still doing an
> extra query for every Desk you pull from your original query.
>
> Funny enough, I was googling around for an answer here, and stumbled
> across this:
>
>
>
>
> On Thu, Feb 26, 2015 at 4:19 AM, aRkadeFR  wrote:
>
>>  got it, so you want to prefetch but not all chairs.
>>
>> I will def follow this thread to see the possibilities of Prefetch :)
>>
>>
>> On 02/26/2015 12:52 PM, Ram Rachum wrote:
>>
>> There may be a big number of chairs, and I don't want all the chairs
>> prefetched. I want to have the database filter them according to the
>> queryset I specified in a single call, I don't want to filter them in
>> Python 

Re: Can the new `Prefetch` solve my problem?

2015-02-26 Thread James Schneider
Heh, I just realized that aRkadeFR had replied with a similar idea to use a
property. At least I know I'm not too far off on my thinking. :-D

-James

On Thu, Feb 26, 2015 at 11:02 AM, James Schneider 
wrote:

> Whoops, accidentally sent that last one too early, here's the continuation:
>
> However, that probably doesn't buy you much since you are still doing an
> extra query for every Desk you pull from your original query.
>
> Funny enough, I was googling around for an answer here, and stumbled
> across this:
>
>
> https://docs.djangoproject.com/en/1.7/ref/models/queries/#django.db.models.Prefetch
>
> which I think is what you were referring to initially in your OP. I wasn't
> even aware of its existence. Prefetch() is a helper class for
> prefetch_related(). Taking a quick glance through the source code, I would
> imagine that it probably won't help you much, since the functionality of
> that class only controls the action of prefetch_related().
>
>
> Zooming out a bit, the crux of your problem is this: An attribute you wish
> to populate is not an FK or M2M field, it is an entirely separate Queryset
> with some moderately complex filters. The built-in ORM functionality for
> pre-loading via prefetch/select_related() is expecting a FK or M2M
> relationship and can't  use another queryset AFAIK. The high-level
> functionality of prefetch_related() is probably close to what you want,
> which is to run a single second query to collect all of
> the favorite_or_nearby_chairs for all of the Desks in your original query,
> and then glue everything together behind the scenes in Python to make the
> desk_obj.favorite_or_nearby_chairs available seamlessly.
>
> I would then wonder if there is another way to organize this data to make
> it easier to work with? How about adding a 'favorite_chairs' field to the
> Desk model that has an M2M to Chair? I would also update your
> 'nearby_desks' model field to use 'nearby_chairs' as the related_field.
>
> Then you could do something like the following:
>
> desks = Desk.objects.filter().select_related('nearby_chairs',
> 'favorite_chairs')
>
> Then, you can modify your model with a property that will return the
> concatenation of nearby_chairs and favorite_chairs:
>
> class Desk(models.Model):
> @property
> def favorite_or_nearby_chairs(self):
> return self.nearby_chairs.all() + self.favorite_chairs
>
> I don't believe this will spawn another query, since select_related() will
> have already run and have the results cached. You may also want to consider
> moving 'nearby_desks' out of Chair and renaming it to 'nearby_chairs' in
> Desk, and using a related_name of 'nearby_desks' instead. Then you can
> remove the .all() from the property definition from above and it definitely
> won't spawn a query. Obviously you'll need to create other processes that
> will populate desk.favorite_chairs, which may or may not be feasible.
>
> TL;DR; I don't believe you can pre-fetch anything because of the extra SQL
> logic needed to calculate the favorite_or_nearby_chairs attribute. It might
> be possible via raw SQL though. Reformatting your data models may lead to
> an easier time since you can then take advantage of the some of the
> optimizations Django offers.
>
> I'm slightly out in right field on this one, so YMMV, but taking a hard
> look at the current model design would be where I would start to try and
> eliminate the need for that custom queryset.
>
> Again, the django-debug-toolbar is your friend in these cases, but
> obviously a high number of even relatively fast queries can have a
> detrimental effect on your load times. Also ensure that the fields you are
> using to filter contain indexes, if appropriate/available.
>
> -James
>
>
>
>
> On Thu, Feb 26, 2015 at 10:17 AM, James Schneider  > wrote:
>
>> Yep, looks like I misunderstood.
>>
>> So, you want to have something like this pseudo code:
>>
>> desks = Desk.objects.filter()
>> for desk in desks:
>> print desk.favorite_or_nearby_chairs
>>
>> And have favorite_or_nearby_chairs be pre-populated with your Chair
>> queryset mentioned earlier?
>>
>> Due to the nature of the custom Chair queryset, I doubt you can do any
>> sort of pre-fetching that would reduce the number of queries. You can
>> probably simulate the effect of prefetch_related() though by overriding the
>> __init__() method of your Desk model, and having the Desk model
>> populate favorite_or_nearby_chairs whenever a Desk object is created.
>>
>> class Desk(models.Model)
>> def __init__(self):
>> # using list() to force the queryset to be evaluated
>> self.favorite_or_nearby_chairs = list()
>>
>>
>> However, that probably doesn't buy you much since you are still doing an
>> extra query for every Desk you pull from your original query.
>>
>> Funny enough, I was googling around for an answer here, and stumbled
>> across this:
>>
>>
>>
>>
>> On Thu, Feb 26, 2015 at 4:19 AM, aRkadeFR  wrote:
>>
>>>  got it, so you want to prefet

Re: Research: Translations od documentation

2015-02-26 Thread Russell Keith-Magee
On Thu, Feb 26, 2015 at 9:51 PM, Tomáš Ehrlich 
wrote:

> Hi Tim,
> I'm aware that it's possible to translate Django documentation. I also
> know that it's translated to french only.
>
> My question is one step behind: Does it makes sense to translate Django
> documentation and (more important) keep it updated? Would anyone use it? Is
> English language the common tongue for programmers? Why is Django docs
> translated to one language only? There isn't enough translators or users
> just don't find it useful?
>
> I asked the same question in Czech django user group and most of them
> agreed that it doesn't make sense to translate whole Django documentation.
> It would make sense to translate materials for beginners, like tutorials,
> django book, etc.
>
> So, at the moment, I don't care about the *tool* or *process*. I'm trying
> to figure it out if there is some kind of motivation to do this stuff.
>

You're going to be in a much better position to judge this that we will.
You're in the middle of a Czech language community; if you were to spend a
week of volunteer time translating the tutorial, do you think it would help
enough people in that community to make the exercise worthwhile?
Ironically, the one place you're *not* going to get a good answer is this
mailing list - because the audience for your translation aren't going to be
able to read it.

>From the perspective of a native English speakers, it makes sense to me
that people would want to have translations in their native languages. What
I don't know is how many Czech speakers speak English well enough that
translating the tutorial wouldn't yield any real benefit. My usual
experience of non-English speaking Europeans is that they speak better
English than I do :-) - but I don't know if that's just selection bias, and
I'm not talking to the ones that don't speak English.

So - it really comes down to how you want to spend your efforts, and your
understanding of the needs of your language community.

Yours,
Russ Magee %-)

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