Re: Django models relation about user user_group asset asset group

2015-09-17 Thread
I think you shoud use ForeignKey.

2015-09-17 23:49 GMT+08:00 周建华 :

> I have design the base model like this:
>
> class User
> some user attr
>
> class UserGroup
> some user_group attr
>
> class Asset
>...
>
> class AssetGroup
>...
>
>
> I want to authorize asset and asset_group to user or user_group, I have no
> good idea about the models design
>
> If i set like this:
>
> class UserAsset
> user = ..
> asset = ...
>
> class UserAssetGroup
>user = ..
>asset_group = ...
>
> class UserGroupAsset
>user_group =
>asset =
>
> class UserGroupAssetGroup
> user_group =
> asset_group = ..
>
>
> If I check the user  have the asset permission or not , i will check the
> user or user group of the user isn't have the asset permission,  the user
> or user group have the asset group(the asset belong to)  permission   .
> It's will check more than 10 tables.
>
>
>
>
>
> --
> 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/9444a015-85d0-43d3-972d-cd07cda5617c%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Help

2015-09-17 Thread Stoo Johnston
Perhaps if you told us all what you would like help with, someone can
help you?

Stoo

On Tue, Sep 15, 2015 at 02:32:40PM -0500, Charly Román wrote:
> NO
> 
> Charly Román
> Software Developer
> http://croman.mx
> 
> 2015-09-15 12:46 GMT-05:00 Cassanova Rumor :
> 
> > --
> > 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/1942d283-caa9-423e-b934-f91754f73346%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/CABeWMUZCQC9%2BbCiy-7EF4DFYar%2B%3DLNu0qGHPsMJZ%2BKTYdag5Jw%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/20150918005629.GA1326%40jadzia.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: PGP signature


Django choice_set feeding from model class objects

2015-09-17 Thread Zoltan Kohalmy
Hey everyone!

Say we have a:

class Friends(models.Model):
person_name = models.CharField(max_length=50)

so this will later on give us instances, like: 'Ben', 'Peter', 'Tom'

class Myself(models.Mode):
your_name = models.CharField(max_length=50)

and here I wish to add a dropdown/radio ChoiceField which feeds from 
Friends' names.
How do I do that?

Thank you very much in advance!!!

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


Re: Prefetch() with through models

2015-09-17 Thread Erik Cederstrand

> Den 16/09/2015 kl. 19.08 skrev Simon Charette :
> 
> If you want to use this approach I'm afraid you'll have to do
> what prefetch_related does under the hood by yourself.
> 
> e.g.
> 
> from collections import defaultdict
> 
> prefetched = defaultdict(list)
> subjects = Subject.objects.filter(...)
> lessons = Lesson.objects.filter(...)
> for lesson_subject in 
> Lesson.subjects.through.objects.filter(lesson__in=lessons, 
> subject__in=subject).select_related('subject').iterator():
> prefetched[lesson_subject.lesson_id].append(lesson_subject.subject)

I hacked up a quick solution that works for my limited requirements. No chained 
querysets, limited prefetch recursion, no order_by, extras etc. But maybe 
someone finds it useful: 
https://gist.github.com/ecederstrand/6748a3496acdc95e40ef

At least it speeds up my queries exponentially; 10-50x improvement in my tests 
so far.

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/6E808964-026D-40B4-BD59-52E13EC4CFF2%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Django deployment

2015-09-17 Thread Hugo Kitano
What is the nginx config? And where do I find it?

On Tuesday, September 15, 2015 at 12:46:40 PM UTC-7, Shawn Milochik wrote:
>
> It's very simple. Just follow these instructions:
>
> http://milocast.com/flasknginx.html
>
> Instead of the final line (gunicorn filename:appname -b 127.0.0.1:), 
> use this:
>
> ./manage.py run_gunicorn -b 127.0.0.1:
>
>

-- 
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/6060640a-2e4f-4806-b9ed-872008c58053%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django deployment

2015-09-17 Thread Hugo Kitano
I'm having trouble deciphering what a APPMODULE is: 
$(MODULE_NAME):$(VARIABLE_NAME)

What does Module_Name and Variable_NAME refer to in the context of a Django 
project named "stats"?

Thanks


On Tuesday, September 15, 2015 at 1:02:59 PM UTC-7, Michiel Overtoom wrote:
>
> Hi Hugo, 
>
> > I keep hearing that Django deployment is unnecessarily difficult. 
>
> Who says this? And what are the reasons they give for it? 
>
>
> > For a website with very little traffic, and for somebody who's new to it 
> all, what is the best way to deploy? And how should I go about deploying! 
>
> I can tell you how I do it, which is not necessarily the simplest way nor 
> especially suited to low traffic. But it's not that hard. On the server 
> machine, I install nginx, gunicorn, django and supervisor. Nginx will be 
> the frontend, gunicorn will be the webserver, django is the application 
> server, and supervisor will be used to start/stop/restart the web 
> application. 
>
> I basically did the same as Shawn. In my supervisord.conf I have these 
> lines: 
>
>   [program:myapp] 
>   command=/usr/local/bin/gunicorn myapp.wsgi -b 127.0.0.1: 
>   directory=/wwwapp/myapp/my 
>   environment=PATH="%(ENV_PATH)s:/usr/local/bin" 
>   user=root 
>   autostart=true 
>   autorestart=true 
>   stdout_logfile=NONE 
>   stderr_logfile=NONE 
>
> I also wrote a blog article about this subject: 
> http://www.michielovertoom.com/freebsd/flask-gunicorn-nginx-supervisord/ 
> which uses Flask as an example, but as Shawn said, it's easy to plug in 
> your Django app instead. 
>
>

-- 
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/bb609edc-df8c-4ec1-b8c2-5b8d5a07386b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


set_expiry() method not work as per the documentation

2015-09-17 Thread parthasarathi panda
I want to clear the session and auto redirect the user to login page if the 
user is idle for some specific time .

i found , by using set_expiry() function we can set the idle time ,but 
actually it clear the session after the specific time even if the user is 
not idle .

i handle the above situation  by setting the set_expiry(get_expiry()) 
 function on each request .

but it dose not redirect the user automatically ,instead after the idle 
time out if the user click any link then only it redirect to login page.

how to auto redirect after idle time out ? plz help .   

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


M2M with through model gives error fields.E336

2015-09-17 Thread Colin Ellis
 Greetings, 

I'm trying to create a M2M relation between an abstract base class and a 
model that extends the same base. 

I have the following code: 

#Base object: 
class BaseObject(models.Model): 
datetime = models.DateTimeField(auto_now_add=True) 
shared = models.ManyToManyField('userprofile.UserProfile', 
through='models_bases.SharedObject', 
symmetrical=False, 

related_name="%(app_label)s_%(class)s_related") 

class Meta: 
abstract = True 

 

and the through table: 

#Through table: 
class SharedObject(models.Model): 
from userprofile.models import UserProfile 

class Meta: 
db_table = 'shared_object' 
userprofile = models.ForeignKey(UserProfile) 
content_type = models.ForeignKey(ContentType) 
object_pk = models.PositiveIntegerField() 
shared_object = GenericForeignKey( 
ct_field="content_type", 
fk_field="object_pk") 
datetime = models.DateTimeField(auto_now_add=True) 


when I go to do ./manage.py makemigrations I get the following errors: 

SystemCheckError: System check identified some issues: 

ERRORS: 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'author.Author.shared', but it does not have a 
foreign key to 'Author' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'award.Award.shared', but it does not have a foreign 
key to 'Award' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'book.Book.shared', but it does not have a foreign 
key to 'Book' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'publisher.Publisher.shared', but it does not have a 
foreign key to 'Publisher' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'rlcomments.RLComment.shared', but it does not have a 
foreign key to 'RLComment' or 'UserProfile'. 
models_bases.SharedObject: (fields.E336) The model is used as an 
intermediate model by 'statusposts.StatusPost.shared', but it does not have 
a foreign key to 'StatusPost' or 'UserProfile'. 


The models are all extensions of BaseObject (including UserProfile). 

I have found this ticket: https://code.djangoproject.com/ticket/11760#no1  
which I believe to be related. 

My question is how do i achieve a M2M with an abstract base that uses a 
through table? 


-- 
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/db47604e-c8cd-46fb-9f44-e09f8372a8d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Advanced Annotate

2015-09-17 Thread Carsten Fuchs

Hi Paolo,

Am 16.09.2015 um 22:52 schrieb Paolo C.:

[...], I need to annotate not only the price but also which is the book that
has that max value.


Isn't that exactly what I was wondering about, too?

	"1) Is there a way to annotate each Store object with the actual Book objects related 
to the minimum and maximum prices?"


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


Django models relation about user user_group asset asset group

2015-09-17 Thread 周建华
I have design the base model like this:

class User
some user attr

class UserGroup 
some user_group attr

class Asset
   ...

class AssetGroup
   ...


I want to authorize asset and asset_group to user or user_group, I have no 
good idea about the models design

If i set like this:

class UserAsset
user = ..
asset = ...

class UserAssetGroup
   user = ..
   asset_group = ...

class UserGroupAsset
   user_group = 
   asset = 

class UserGroupAssetGroup
user_group = 
asset_group = ..


If I check the user  have the asset permission or not , i will check the 
user or user group of the user isn't have the asset permission,  the user 
or user group have the asset group(the asset belong to)  permission   . 
It's will check more than 10 tables.





-- 
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/9444a015-85d0-43d3-972d-cd07cda5617c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Integrating RabbitMQ with Django

2015-09-17 Thread Felipe Arenhardt Tomaz
I update my gist and put 2 other files [1]

An init script (/etc/init.d/script) and an Django Command.

[1] https://gist.github.com/Arenhardt/8ac7e7667134c28eceed

--
Felipe Arenhardt Tomaz
Systems Developer
Curitiba - Paraná
www.felipetomaz.com

On Thu, Sep 17, 2015 at 10:57 AM, Erol Merdanović 
wrote:

> @Felipe
>
> Can you show an example what you mean by init script?
>
> On Thursday, 17 September 2015 15:18:02 UTC+2, Felipe Tomaz wrote:
>>
>> I don't like to put the commands on supervisor. You can create an init
>> script.
>>
>> --
>> Felipe Arenhardt Tomaz
>> Systems Developer
>> Curitiba - Paraná
>> www.felipetomaz.com
>>
>> On Thu, Sep 17, 2015 at 4:48 AM, Erol Merdanović 
>> wrote:
>>
>>> @Felipe
>>>
>>> Yes, I use very similar approach. Thank you for the example.
>>>
>>> I found a great project https://github.com/rfk/django-supervisor that
>>> enables me to run Django commands under supervisor. I will test it and let
>>> you know how it goes.
>>>
>>> On Wednesday, 16 September 2015 19:38:59 UTC+2, Felipe Tomaz wrote:

 I create and use this class to manipulate the queues

 https://gist.github.com/Arenhardt/8ac7e7667134c28eceed

 --
 Felipe Arenhardt Tomaz
 Systems Developer
 Curitiba - Paraná
 www.felipetomaz.com

 On Wed, Sep 16, 2015 at 2:01 PM, Erol Merdanović 
 wrote:

> @Tom
>
> Yes, it was also thinking about using supervisord. But I'm interested
> if there is anything else that nicely integrates into Django.
>
> @Felipe
>
> Yes, I'm using pika. Afaik there are no decent tutorials how to
> implement consumers into Django.
>
> On Wednesday, 16 September 2015 16:05:26 UTC+2, Felipe Tomaz wrote:
>>
>> For manual manipulation recommend Pika[1]
>>
>> [1] https://pypi.python.org/pypi/pika
>>
>> --
>> Felipe Arenhardt Tomaz
>> Systems Developer
>> Curitiba - Paraná
>> www.felipetomaz.com
>>
>> On Wed, Sep 16, 2015 at 10:53 AM, Erol Merdanović 
>> wrote:
>>
>>> @Vijay
>>>
>>> Yes, source of the messages is outside of the Django application. I
>>> could use some transformers, but again, it's extra moving part.
>>>
>>> @Sadaf
>>>
>>> Ok, thank you for the blog. I will check it out. But again, Celery
>>> is great but I'm not really sure it solves my problem.
>>>
>>> On Wednesday, 16 September 2015 15:34:54 UTC+2, Sadaf Noor wrote:

 Instead you can try using celery. For demonstration purpose I have
 tried an image processing app using rabbitmq, celery with flask. It 
 worked
 great. It can be found at my blog (
 http://www.sadafnoor.com/blog/rabbitmq-celery-demonstration-using-image-processing-app-on-flask/
 ).
 On 16-Sep-2015 6:53 PM, "Erol Merdanović" 
 wrote:

> Hi all
>
> I'm using Django to develop a service. Service connects to
> RabbitMQ and receives events that are translated to
> creating/updating/deleting of the database records.
>
> What is the best way to run RabbitMQ consumer with Django? I'm
> using Pika library and I run consumer as a management command (python
> manage.py listen_to_changes). Is this a good solution? I don't see it 
> so.
> I'm running Django as WSGI so I presume there are no start/stop Django
> events that I could plugin in to start/stop consumer.
>
> I'm aware of the Celery and how it nicely integrates into Django,
> but for me it's not an option.
>
> What do you suggest? How to run RabbitMQ with Django (stability is
> the main objective).
>
> --
> 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/e2b0cfd3-f33f-485c-9497-98fd281c9cd2%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...@googlegroups.com.
>>> To post to this group, send email to 

Re: Integrating RabbitMQ with Django

2015-09-17 Thread Erol Merdanović
@Felipe

Can you show an example what you mean by init script?

On Thursday, 17 September 2015 15:18:02 UTC+2, Felipe Tomaz wrote:
>
> I don't like to put the commands on supervisor. You can create an init 
> script.
>
> --
> Felipe Arenhardt Tomaz
> Systems Developer
> Curitiba - Paraná
> www.felipetomaz.com
>
> On Thu, Sep 17, 2015 at 4:48 AM, Erol Merdanović  > wrote:
>
>> @Felipe
>>
>> Yes, I use very similar approach. Thank you for the example.
>>
>> I found a great project https://github.com/rfk/django-supervisor that 
>> enables me to run Django commands under supervisor. I will test it and let 
>> you know how it goes.
>>
>> On Wednesday, 16 September 2015 19:38:59 UTC+2, Felipe Tomaz wrote:
>>>
>>> I create and use this class to manipulate the queues
>>>
>>> https://gist.github.com/Arenhardt/8ac7e7667134c28eceed
>>>
>>> --
>>> Felipe Arenhardt Tomaz
>>> Systems Developer
>>> Curitiba - Paraná
>>> www.felipetomaz.com
>>>
>>> On Wed, Sep 16, 2015 at 2:01 PM, Erol Merdanović  
>>> wrote:
>>>
 @Tom

 Yes, it was also thinking about using supervisord. But I'm interested 
 if there is anything else that nicely integrates into Django.

 @Felipe

 Yes, I'm using pika. Afaik there are no decent tutorials how to 
 implement consumers into Django.

 On Wednesday, 16 September 2015 16:05:26 UTC+2, Felipe Tomaz wrote:
>
> For manual manipulation recommend Pika[1]
>
> [1] https://pypi.python.org/pypi/pika
>
> --
> Felipe Arenhardt Tomaz
> Systems Developer
> Curitiba - Paraná
> www.felipetomaz.com
>
> On Wed, Sep 16, 2015 at 10:53 AM, Erol Merdanović  
> wrote:
>
>> @Vijay
>>
>> Yes, source of the messages is outside of the Django application. I 
>> could use some transformers, but again, it's extra moving part.
>>
>> @Sadaf
>>
>> Ok, thank you for the blog. I will check it out. But again, Celery is 
>> great but I'm not really sure it solves my problem.
>>
>> On Wednesday, 16 September 2015 15:34:54 UTC+2, Sadaf Noor wrote:
>>>
>>> Instead you can try using celery. For demonstration purpose I have 
>>> tried an image processing app using rabbitmq, celery with flask. It 
>>> worked 
>>> great. It can be found at my blog ( 
>>> http://www.sadafnoor.com/blog/rabbitmq-celery-demonstration-using-image-processing-app-on-flask/
>>>  
>>> ).
>>> On 16-Sep-2015 6:53 PM, "Erol Merdanović"  wrote:
>>>
 Hi all

 I'm using Django to develop a service. Service connects to RabbitMQ 
 and receives events that are translated to creating/updating/deleting 
 of 
 the database records. 

 What is the best way to run RabbitMQ consumer with Django? I'm 
 using Pika library and I run consumer as a management command (python 
 manage.py listen_to_changes). Is this a good solution? I don't see it 
 so. 
 I'm running Django as WSGI so I presume there are no start/stop Django 
 events that I could plugin in to start/stop consumer.

 I'm aware of the Celery and how it nicely integrates into Django, 
 but for me it's not an option.

 What do you suggest? How to run RabbitMQ with Django (stability is 
 the main objective).

 -- 
 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/e2b0cfd3-f33f-485c-9497-98fd281c9cd2%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...@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/a1b78c97-eddb-4330-96e9-b442fe6609bd%40googlegroups.com
>>  
>> 

Re: Integrating RabbitMQ with Django

2015-09-17 Thread Felipe Arenhardt Tomaz
I don't like to put the commands on supervisor. You can create an init
script.

--
Felipe Arenhardt Tomaz
Systems Developer
Curitiba - Paraná
www.felipetomaz.com

On Thu, Sep 17, 2015 at 4:48 AM, Erol Merdanović 
wrote:

> @Felipe
>
> Yes, I use very similar approach. Thank you for the example.
>
> I found a great project https://github.com/rfk/django-supervisor that
> enables me to run Django commands under supervisor. I will test it and let
> you know how it goes.
>
> On Wednesday, 16 September 2015 19:38:59 UTC+2, Felipe Tomaz wrote:
>>
>> I create and use this class to manipulate the queues
>>
>> https://gist.github.com/Arenhardt/8ac7e7667134c28eceed
>>
>> --
>> Felipe Arenhardt Tomaz
>> Systems Developer
>> Curitiba - Paraná
>> www.felipetomaz.com
>>
>> On Wed, Sep 16, 2015 at 2:01 PM, Erol Merdanović 
>> wrote:
>>
>>> @Tom
>>>
>>> Yes, it was also thinking about using supervisord. But I'm interested if
>>> there is anything else that nicely integrates into Django.
>>>
>>> @Felipe
>>>
>>> Yes, I'm using pika. Afaik there are no decent tutorials how to
>>> implement consumers into Django.
>>>
>>> On Wednesday, 16 September 2015 16:05:26 UTC+2, Felipe Tomaz wrote:

 For manual manipulation recommend Pika[1]

 [1] https://pypi.python.org/pypi/pika

 --
 Felipe Arenhardt Tomaz
 Systems Developer
 Curitiba - Paraná
 www.felipetomaz.com

 On Wed, Sep 16, 2015 at 10:53 AM, Erol Merdanović 
 wrote:

> @Vijay
>
> Yes, source of the messages is outside of the Django application. I
> could use some transformers, but again, it's extra moving part.
>
> @Sadaf
>
> Ok, thank you for the blog. I will check it out. But again, Celery is
> great but I'm not really sure it solves my problem.
>
> On Wednesday, 16 September 2015 15:34:54 UTC+2, Sadaf Noor wrote:
>>
>> Instead you can try using celery. For demonstration purpose I have
>> tried an image processing app using rabbitmq, celery with flask. It 
>> worked
>> great. It can be found at my blog (
>> http://www.sadafnoor.com/blog/rabbitmq-celery-demonstration-using-image-processing-app-on-flask/
>> ).
>> On 16-Sep-2015 6:53 PM, "Erol Merdanović"  wrote:
>>
>>> Hi all
>>>
>>> I'm using Django to develop a service. Service connects to RabbitMQ
>>> and receives events that are translated to creating/updating/deleting of
>>> the database records.
>>>
>>> What is the best way to run RabbitMQ consumer with Django? I'm using
>>> Pika library and I run consumer as a management command (python 
>>> manage.py
>>> listen_to_changes). Is this a good solution? I don't see it so. I'm 
>>> running
>>> Django as WSGI so I presume there are no start/stop Django events that I
>>> could plugin in to start/stop consumer.
>>>
>>> I'm aware of the Celery and how it nicely integrates into Django,
>>> but for me it's not an option.
>>>
>>> What do you suggest? How to run RabbitMQ with Django (stability is
>>> the main objective).
>>>
>>> --
>>> 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/e2b0cfd3-f33f-485c-9497-98fd281c9cd2%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...@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/a1b78c97-eddb-4330-96e9-b442fe6609bd%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 

Re: Django authentication using phone number

2015-09-17 Thread Rafael E. Ferrero
https://docs.djangoproject.com/en/1.8/topics/auth/customizing/

--
Rafael E. Ferrero

2015-09-17 2:31 GMT-03:00 Ravi Chityala :

> I am looking for an django app to do authentication and authorization
> using phone number. Apps like django-registration can use email address or
> user name for authentication but my requirements are different. I used all
> my googlefu but could not find a single django app that does it. Does
> anybody have any idea?  The functionality I am looking for are listed below
>
> TL;DR - Need a django app where phone number is the user name. Password is
> created by django and text message is sent to user. Need to create a django
> user object when logging.
>
> Complete detail:
>
>1. The user enters name, phone number and few other details. A text
>message needs to be sent using Twilio with a 5 digit randomly generated
>code.  The code needs to be hashed and stored in the database. The message
>sending can be abstracted, so that other services can also be used.
>2. The user will use the code to login. The hashed version of the
>entered code is compared to the one stored in the database. If they match,
>the user will be allowed to login.
>3. If the user wants to reset the code, a new code needs to be
>generated and sent. The new code will be hashed and stored in the database.
>4. When the user is authenticated, a user object needs to be created,
>so that I can use the request.user object for authorization.
>5. This authentication mechanism preferably should work with
>django-rest-framework or tasty pie.
>
> --
> 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/69314e3c-9215-4e94-87a9-044568e96f0c%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/CAJJc_8VLWrUP6ys_nd-68tw%3Dorkyieg-Fws8X2fOjjMmqSMq6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django authentication using phone number

2015-09-17 Thread Ravi Chityala
 I am looking for an django app to do authentication and authorization 
using phone number. Apps like django-registration can use email address or 
user name for authentication but my requirements are different. I used all 
my googlefu but could not find a single django app that does it. Does 
anybody have any idea?  The functionality I am looking for are listed below 

TL;DR - Need a django app where phone number is the user name. Password is 
created by django and text message is sent to user. Need to create a django 
user object when logging. 

Complete detail:

   1. The user enters name, phone number and few other details. A text 
   message needs to be sent using Twilio with a 5 digit randomly generated 
   code.  The code needs to be hashed and stored in the database. The message 
   sending can be abstracted, so that other services can also be used.
   2. The user will use the code to login. The hashed version of the 
   entered code is compared to the one stored in the database. If they match, 
   the user will be allowed to login.
   3. If the user wants to reset the code, a new code needs to be generated 
   and sent. The new code will be hashed and stored in the database.
   4. When the user is authenticated, a user object needs to be created, so 
   that I can use the request.user object for authorization. 
   5. This authentication mechanism preferably should work with 
   django-rest-framework or tasty pie.

-- 
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/69314e3c-9215-4e94-87a9-044568e96f0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


NoReverseMatch password_reset Error

2015-09-17 Thread Martin Jablečník
Hello, on Stackoverflow I created this question: 
http://stackoverflow.com/questions/32625997/upgrade-django-and-noreversematch-password-error
Do you know anybody how can I fix it? 
I tried somethong from this: 
https://docs.djangoproject.com/en/1.8/releases/1.6/#django-contrib-auth-password-reset-uses-base-64-encoding-of-user-pk
but it didn't help me.

-- 
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/3643f04e-56c5-44e4-bc7c-7a7660911cea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Using Django as dependency in an API

2015-09-17 Thread Thierry
Hi everybody,

Django has got many features really interesting to reuse in APIs like its 
builtin ORM or template engine.

Maybe I'm wrong but it seems required to initalize Django with the 
configure() and setup() functions to register models and databases and make 
the glue between several independent modules. All seems based on the 
concept of application and it makes really difficult to distribute APIs 
separately.

How is it possible to avoid this global Django configuration and make this 
configuration at a module level ? For example, to register models in a 
database at module import or define the database backend for a module. 

Cheers,

Thierry.

-- 
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/7e150aa1-b39f-497d-86d8-8fea34fe52b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Integrating RabbitMQ with Django

2015-09-17 Thread Erol Merdanović
@Felipe

Yes, I use very similar approach. Thank you for the example.

I found a great project https://github.com/rfk/django-supervisor that 
enables me to run Django commands under supervisor. I will test it and let 
you know how it goes.

On Wednesday, 16 September 2015 19:38:59 UTC+2, Felipe Tomaz wrote:
>
> I create and use this class to manipulate the queues
>
> https://gist.github.com/Arenhardt/8ac7e7667134c28eceed
>
> --
> Felipe Arenhardt Tomaz
> Systems Developer
> Curitiba - Paraná
> www.felipetomaz.com
>
> On Wed, Sep 16, 2015 at 2:01 PM, Erol Merdanović  > wrote:
>
>> @Tom
>>
>> Yes, it was also thinking about using supervisord. But I'm interested if 
>> there is anything else that nicely integrates into Django.
>>
>> @Felipe
>>
>> Yes, I'm using pika. Afaik there are no decent tutorials how to implement 
>> consumers into Django.
>>
>> On Wednesday, 16 September 2015 16:05:26 UTC+2, Felipe Tomaz wrote:
>>>
>>> For manual manipulation recommend Pika[1]
>>>
>>> [1] https://pypi.python.org/pypi/pika
>>>
>>> --
>>> Felipe Arenhardt Tomaz
>>> Systems Developer
>>> Curitiba - Paraná
>>> www.felipetomaz.com
>>>
>>> On Wed, Sep 16, 2015 at 10:53 AM, Erol Merdanović  
>>> wrote:
>>>
 @Vijay

 Yes, source of the messages is outside of the Django application. I 
 could use some transformers, but again, it's extra moving part.

 @Sadaf

 Ok, thank you for the blog. I will check it out. But again, Celery is 
 great but I'm not really sure it solves my problem.

 On Wednesday, 16 September 2015 15:34:54 UTC+2, Sadaf Noor wrote:
>
> Instead you can try using celery. For demonstration purpose I have 
> tried an image processing app using rabbitmq, celery with flask. It 
> worked 
> great. It can be found at my blog ( 
> http://www.sadafnoor.com/blog/rabbitmq-celery-demonstration-using-image-processing-app-on-flask/
>  
> ).
> On 16-Sep-2015 6:53 PM, "Erol Merdanović"  wrote:
>
>> Hi all
>>
>> I'm using Django to develop a service. Service connects to RabbitMQ 
>> and receives events that are translated to creating/updating/deleting of 
>> the database records. 
>>
>> What is the best way to run RabbitMQ consumer with Django? I'm using 
>> Pika library and I run consumer as a management command (python 
>> manage.py 
>> listen_to_changes). Is this a good solution? I don't see it so. I'm 
>> running 
>> Django as WSGI so I presume there are no start/stop Django events that I 
>> could plugin in to start/stop consumer.
>>
>> I'm aware of the Celery and how it nicely integrates into Django, but 
>> for me it's not an option.
>>
>> What do you suggest? How to run RabbitMQ with Django (stability is 
>> the main objective).
>>
>> -- 
>> 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/e2b0cfd3-f33f-485c-9497-98fd281c9cd2%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...@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/a1b78c97-eddb-4330-96e9-b442fe6609bd%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...@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/ec65ffec-0b14-4a17-a15f-6899a3575cca%40googlegroups.com
>>  
>> 

Re: Prefetch() with through models

2015-09-17 Thread Erik Cederstrand

> Den 17/09/2015 kl. 09.22 skrev Javier Guerra Giraldez :
> 
> On Thu, Sep 17, 2015 at 2:07 AM, Erik Cederstrand
>  wrote:
>>> Den 16/09/2015 kl. 16.45 skrev Mike Dewhirst :
>>> 
>>> On 16/09/2015 9:53 AM, Erik Cederstrand wrote:
 issues because the prefetch query does something along the lines of
 "SELECT ... FROM lesson_subjects WHERE lesson_id IN
 [insane_list_of_lesson_ids]".
>>> 
>>> I'm no expert so I'm wondering if len([insane_list_of_lesson_ids]) == 
>>> "hundreds of thousands"?
>> 
>> In my, case, yes. I think the backend might process the query in chunks if 
>> the length of the SQL exceeds the max SQL query size.
> 
> 
> Just curious, which RDBMS are you using?  I remember that on MySQL
> there used to be an advice to populate a temporary table and do a JOIN
> instead of very big `xxx IN ()` statements.  I'm not sure if
> there's a hard limit, but anything over a few hundreds would be better
> with JOIN than with IN(...)

I'm using PostgreSQL and yes, I'm sure there are techniques to work around huge 
IN clauses. It just seems plain wrong to send 1-2MB of textual SQL to an SQL 
server when my original filters should work just fine, and hopefully much 
faster.

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/6FC97256-8DC7-4E68-ACDA-FCD459F5D519%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Prefetch() with through models

2015-09-17 Thread Javier Guerra Giraldez
On Thu, Sep 17, 2015 at 2:07 AM, Erik Cederstrand
 wrote:
>> Den 16/09/2015 kl. 16.45 skrev Mike Dewhirst :
>>
>> On 16/09/2015 9:53 AM, Erik Cederstrand wrote:
>>> issues because the prefetch query does something along the lines of
>>> "SELECT ... FROM lesson_subjects WHERE lesson_id IN
>>> [insane_list_of_lesson_ids]".
>>
>> I'm no expert so I'm wondering if len([insane_list_of_lesson_ids]) == 
>> "hundreds of thousands"?
>
> In my, case, yes. I think the backend might process the query in chunks if 
> the length of the SQL exceeds the max SQL query size.


Just curious, which RDBMS are you using?  I remember that on MySQL
there used to be an advice to populate a temporary table and do a JOIN
instead of very big `xxx IN ()` statements.  I'm not sure if
there's a hard limit, but anything over a few hundreds would be better
with JOIN than with IN(...)

With Oracle, there _is_ a hard limit, and a not very high one.  I've
hit it frequently when doing exploratory SQL on SQLDeveloper.  For
anything over a thousand items, it's safer to go the temporary table
route.

The only one where I haven't been able to hit any limit is PostgreSQL.
There i routinely do many thousands of items and it works beautifully.
I haven't personally tried "hundreds of thousands", but I guess that
if it fits within some maximum textual representation, then it will
handle it.


-- 
Javier

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


Re: Prefetch() with through models

2015-09-17 Thread Erik Cederstrand

> Den 16/09/2015 kl. 16.45 skrev Mike Dewhirst :
> 
> On 16/09/2015 9:53 AM, Erik Cederstrand wrote:
>> Hi folks,
>> 
>> I'm working on a school timetable app. I want to fetch hundreds of
>> thousands of Lesson instances with prefetched m2m relations (e.g.
>> subjects). My m2m relations use through models (I'm not sure this
>> actually makes a difference here), and I'm running into performance
>> issues because the prefetch query does something along the lines of
>> "SELECT ... FROM lesson_subjects WHERE lesson_id IN
>> [insane_list_of_lesson_ids]".
> 
> I'm no expert so I'm wondering if len([insane_list_of_lesson_ids]) == 
> "hundreds of thousands"?

In my, case, yes. I think the backend might process the query in chunks if the 
length of the SQL exceeds the max SQL query size.

I've had a look at the prefetch code in Django 1.8. The prefetcher is designed 
to kick in *after* the QuerySet has constructed the list of objects. It only 
has access to the resulting list of items, not the original SQL filters, so the 
only sane way to fetch related objects is to use an IN clause. I can't see any 
way to replace this with the filters without rewriting the whole prefetch code.

I'll try the route Simon suggested and run the prefetch queries myself. I can 
probably populate the _prefetched_objects_cache on each object so the 
optimization is reasonably transparent to consumers. Prefetching 'foo__bar' 
this way gets more complicated, so I think I'll go with a simple solution first.

> I'm not much help but I do remember many years ago a school timetable 
> programming guru who told me they are definitely not trivial. I think he was 
> referring to timetable creation given enrolments, student preferences, 
> curriculum/course requirements, availability of teachers and location of 
> campuses. One of the main issues (ISTR) was memory - or lack of it.

Constraints solvers to calculate the optimal timetable given a set of (soft or 
hard) requirements and costs is mathematically well understood but insanely 
difficult to get right in practice. Lack of memory and the limited life span of 
human beings are just some of the issues. Luckily, I'm just working on the 
output of that calculation :-)

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/69D8C444-936A-46CA-904A-FC9B4C0CA39D%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.