Saturday, November 30, 2013

Re: python virtual environment

you need to activate the virtualenv before using:
on windows:
env\Scripts\activate
on linux:
source env/bin/activate


On Fri, Nov 29, 2013 at 7:44 PM, tino <tino85@gmail.com> wrote:


Hello

I am trying to run a project that was setup in another server, but getting the following error. I am using python 2.7, django, virtualenv. So I am running the project inside a python virtual environment


(virtualenv)[web.srv1 daily# python manage.py runserver 0.0.0.0:8000
Traceback (most recent call last):
  File "manage.py", line 2, in <module>
    from django.core.management import execute_manager
ImportError: cannot import name execute_manager


I used the method mentioned in the below link to setup the virtual environment.

http://toic.org/blog/2011/wsgi-on-cpanel-improved/

This project was setup inside a cpanel server. But the current server I using is not a cpanel server. It is normal centos server.

Can somebody help me to track down the issue.


--
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+unsubscribe@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/7181ba64-d2d6-4926-b35d-5b4a2a7792a4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAFWa6tLdD23_Tzyy8QfLbCH8ysxVzkukq_5_ORW5VvbTLRBOLA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Difference between signals and celery

No, you can run celery from the same server, the problem is you won't be able to do that on many cheap shared hostings


On Sat, Nov 30, 2013 at 7:35 PM, Robin Lery <robinlery@gmail.com> wrote:
Thank all so much for you replies. Just one more question though. Does this means Celery needs a different server?


On Sat, Nov 30, 2013 at 12:41 AM, Carlos Daniel Ruvalcaba Valenzuela <clsdaniel@gmail.com> wrote:
Signals are like events, for example, when the ORM has done an update. Celery is more like a Task queue, you define code to execute certain task, load it on celery task server which is running separately from your django process, then when you need to execute it in the background you tell it, which usually means sending a message through a broker such as redis or rabbitmq to the task server, then it gets executed.

Celery is for background tasks, such as processing images, doing updates without blocking the main function return, etc. Also celery task can run in another machine, while signals are executed locally.

Regards,
Carlos Ruvalcaba


On Fri, Nov 29, 2013 at 11:52 AM, Robin Lery <robinlery@gmail.com> wrote:

This may be a lame question, but I am really confused with these two. I know signals are used to do some task when something has happened. But what about celery? In the documentation it says:

Celery is an asynchronous task queue/job queue based on distributed message passing.

Will someone please explain to me of what celery is? What's the difference between these two and when to use them? Will be much appreciated! 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+unsubscribe@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/62298d12-02ab-4d34-b8f7-2c4c9bace561%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAEF3qbkT2tzvHUcqLsTbg_gxY-%2BtdFinn%2BER5F-PdEf_QV-zHg%40mail.gmail.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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%2B4-nGqoCrLoc7BY0Le-7izz7w0qO9-LWWzMZixjWPt5_ZGqCw%40mail.gmail.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAFWa6tL29fSivUpzoT-cYL2qQDFj%2Bv5gmepEN%3DWF0du8SJaJSA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: How to get the class name of a ContentType in django

On Sat, Nov 30, 2013 at 3:37 PM, Aamu Padi <aamupadi@gmail.com> wrote:
> Yes!!! Can I use it as a string in template?
>


I haven't tested it but it seems you should be able to assign it to a
context variable or kwargs in a view and use it in a template.

Something like:

context['classname'] = type(myinstance)
or
kwargs['classname'] = type(myinstance)

HTH,
Tim

>
> On Sat, Nov 30, 2013 at 2:45 PM, Timothy W. Cook <tim@mlhim.org> wrote:
>>
>> You can use type() on your instance(s) to find out their model class.
>>
>> If you have an instance of the model:
>>
>> stream = StreamItem.objects.create(user,ct,oid,pdate)
>>
>> Then type(stream) should return <class 'StreamItem'>
>>
>> Is that what you wanted?
>>
>>
>>
>>
>>
>> On Sat, Nov 30, 2013 at 1:14 AM, Simon Charette <charette.s@gmail.com>
>> wrote:
>> > Do you want to retrieve the class name of the model class associated
>> > with a
>> > content type?
>> >
>> > Le jeudi 28 novembre 2013 12:04:34 UTC-5, Aamu Padi a écrit :
>> >>
>> >> How do I get the class name in string of a ContentType? I tried it this
>> >> way, but it didn't worked out:
>> >>
>> >> class StreamItem(models.Model):
>> >> user = models.ForeignKey(User)
>> >> content_type = models.ForeignKey(ContentType)
>> >> object_id = models.PositiveIntegerField()
>> >> pub_date = models.DateTimeField(default=datetime.now)
>> >>
>> >> content_object = generic.GenericForeignKey('content_type',
>> >> 'object_id')
>> >> content_class = content_type.__name__
>> >>
>> >> def __unicode__(self):
>> >> return self.content_class
>> >>
>> >> Any help will be much appreciated! 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+unsubscribe@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/46096fde-2754-49aa-af03-3829a5d1be45%40googlegroups.com.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>> --
>> MLHIM VIP Signup: http://goo.gl/22B0U
>> ============================================
>> Timothy Cook, MSc +55 21 94711995
>> MLHIM http://www.mlhim.org
>> Like Us on FB: https://www.facebook.com/mlhim2
>> Circle us on G+: http://goo.gl/44EV5
>> Google Scholar: http://goo.gl/MMZ1o
>> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
>>
>> --
>> 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+unsubscribe@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%2B%3DOU3XfRZy7XmTwof5QkNB3oe%2BhF0PVJO_XW8SWi9QdxqnFRg%40mail.gmail.com.
>>
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> 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+unsubscribe@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/CAHSNPWsrPg8jC_hmSmgZfuO8KSucjCcb_V4h2PdePUxLwSK3oA%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.



--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

--
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+unsubscribe@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%2B%3DOU3WpkMK95w7xsHXmeHtYubynaqKHQHecLzzGnY9mSfs_Sw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: How to use primary key as an attribute

I'm not sure what you are trying to accomplish. Since the 'pk' field
is going to be defined on your instances anyway, do you need a
'thread_pk' field?

On Sat, Nov 30, 2013 at 3:38 PM, Aamu Padi <aamupadi@gmail.com> wrote:
> This may be a lame question, but how do I use the primary key as a default
> value for an attribute?
>
> This is my models.py:
>
> class Thread(models.Model):
> thread_pk = models.PositiveIntegerField(default=self.pk)
>
> This gives me an error:
>
> self is not defined
>
> How do I go about using the pk as a default value of an attribute? Any help
> will be grateful. Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@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/CAHSNPWs3NSQtzciqYL%2B7C7FL3Ybu1SAQv-L73EL2DNCMpJn7tA%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

--
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+unsubscribe@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%2B%3DOU3UTGKqCM8gtFSGFKat-PYB3u7RzfVyXzA-8mhuLrKmp%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Finished and Published Tango with Rango Tutorials

Presumably you are talking about the left menu being broken and the 'Find a category' not working?

For the first, looks like you are missing a closing div for the top nav bar. Regarding the Find a category not working, I had the same issue and there was a problem in the tutorial with an extra tab that should not have been there. If I recall, the issue was in the suggest_category view and it relates to the following line:

cat_list = get_category_list(8, starts_with)

That line should not be tabbed as shown in the tutorial as the tab causes it to become part of the above else and so cat_list is not populates as expected. Have a look at the final code from the reference site:



On Saturday, 30 November 2013 12:31:13 UTC, Amimo Benja wrote:
Hello, 

I finished the Tango with Rango Tutorials and published the app at amimobenja.pythonanywhere.com/rango/ however it is not working as expected.

Check out the site and review the whole whole code at https://github.com/amimobenja/tango_with_django and recommend any necessary changes. 

--
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+unsubscribe@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/69476e68-6cd3-4c75-87ed-497f398bca10%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Group subscription management

Thanks, Felipe.

For anyone else who might have trouble with this, go to the My Groups item on the left nav bar which displays the groups of which you're a member. Then click the "Edit Memberships" tab at the top. This will give you a drop-down to manage the subscription for all of your groups.

 

On Saturday, November 30, 2013 12:02:23 PM UTC-5, Steve Sawyer wrote:
I am drowning in emails, and I can't seem to figure out how to un-subscribe from everything that gets posted to this group.

I tried to subscribe just to a daily digest so I only get one email a day, but now I can't even find that setting to turn it off, as it appears to also turn on an echo of every individual post into my mailbox.

Can anyone help me out here??


--
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+unsubscribe@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/b502f846-60a5-4221-9065-3e70d15fb5b8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

How to use primary key as an attribute

This may be a lame question, but how do I use the primary key as a default value for an attribute?

This is my models.py:

    class Thread(models.Model):
        thread_pk = models.PositiveIntegerField(default=self.pk)


This gives me an error:

    self is not defined

How do I go about using the pk as a default value of an attribute? Any help will be grateful. Thank you.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/CAHSNPWs3NSQtzciqYL%2B7C7FL3Ybu1SAQv-L73EL2DNCMpJn7tA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: How to get the class name of a ContentType in django

Yes!!! Can I use it as a string in template?


On Sat, Nov 30, 2013 at 2:45 PM, Timothy W. Cook <tim@mlhim.org> wrote:
You can use type() on your instance(s) to find out their model class.

If you have an instance of the model:

stream = StreamItem.objects.create(user,ct,oid,pdate)

Then type(stream) should return <class 'StreamItem'>

Is that what you wanted?





On Sat, Nov 30, 2013 at 1:14 AM, Simon Charette <charette.s@gmail.com> wrote:
> Do you want to retrieve the class name of the model class associated with a
> content type?
>
> Le jeudi 28 novembre 2013 12:04:34 UTC-5, Aamu Padi a écrit :
>>
>> How do I get the class name in string of a ContentType? I tried it this
>> way, but it didn't worked out:
>>
>> class StreamItem(models.Model):
>>     user = models.ForeignKey(User)
>>     content_type = models.ForeignKey(ContentType)
>>     object_id = models.PositiveIntegerField()
>>     pub_date = models.DateTimeField(default=datetime.now)
>>
>>     content_object = generic.GenericForeignKey('content_type',
>> 'object_id')
>>     content_class = content_type.__name__
>>
>>     def __unicode__(self):
>>         return self.content_class
>>
>> Any help will be much appreciated! 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+unsubscribe@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/46096fde-2754-49aa-af03-3829a5d1be45%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc           +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

--
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+unsubscribe@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%2B%3DOU3XfRZy7XmTwof5QkNB3oe%2BhF0PVJO_XW8SWi9QdxqnFRg%40mail.gmail.com.

--
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+unsubscribe@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/CAHSNPWsrPg8jC_hmSmgZfuO8KSucjCcb_V4h2PdePUxLwSK3oA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Difference between signals and celery

Thank all so much for you replies. Just one more question though. Does this means Celery needs a different server?


On Sat, Nov 30, 2013 at 12:41 AM, Carlos Daniel Ruvalcaba Valenzuela <clsdaniel@gmail.com> wrote:
Signals are like events, for example, when the ORM has done an update. Celery is more like a Task queue, you define code to execute certain task, load it on celery task server which is running separately from your django process, then when you need to execute it in the background you tell it, which usually means sending a message through a broker such as redis or rabbitmq to the task server, then it gets executed.

Celery is for background tasks, such as processing images, doing updates without blocking the main function return, etc. Also celery task can run in another machine, while signals are executed locally.

Regards,
Carlos Ruvalcaba


On Fri, Nov 29, 2013 at 11:52 AM, Robin Lery <robinlery@gmail.com> wrote:

This may be a lame question, but I am really confused with these two. I know signals are used to do some task when something has happened. But what about celery? In the documentation it says:

Celery is an asynchronous task queue/job queue based on distributed message passing.

Will someone please explain to me of what celery is? What's the difference between these two and when to use them? Will be much appreciated! 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+unsubscribe@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/62298d12-02ab-4d34-b8f7-2c4c9bace561%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAEF3qbkT2tzvHUcqLsTbg_gxY-%2BtdFinn%2BER5F-PdEf_QV-zHg%40mail.gmail.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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%2B4-nGqoCrLoc7BY0Le-7izz7w0qO9-LWWzMZixjWPt5_ZGqCw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Group subscription management

Go to groups.google.com and manage your groups!

-----------------------------------     Felipe Brunelli de Andrade    http://www.fandrade.com.br/  -----------------------------------  Cel: (16) 98121-5290  Skype: fbruandrade  -----------------------------------


2013/11/30 Steve Sawyer <ssawyer92@gmail.com>
I am drowning in emails, and I can't seem to figure out how to un-subscribe from everything that gets posted to this group.

I tried to subscribe just to a daily digest so I only get one email a day, but now I can't even find that setting to turn it off, as it appears to also turn on an echo of every individual post into my mailbox.

Can anyone help me out here??


--
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+unsubscribe@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/3ad39a03-806b-4bbd-bc0d-a3bdbd249d38%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAEYpY_Jj%2BKXbapywQM92Mfnh21_aKikdcAA6GLBGZmg76NDfdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Group subscription management

I am drowning in emails, and I can't seem to figure out how to un-subscribe from everything that gets posted to this group.

I tried to subscribe just to a daily digest so I only get one email a day, but now I can't even find that setting to turn it off, as it appears to also turn on an echo of every individual post into my mailbox.

Can anyone help me out here??


--
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+unsubscribe@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/3ad39a03-806b-4bbd-bc0d-a3bdbd249d38%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Finished and Published Tango with Rango Tutorials

Hello, 

I finished the Tango with Rango Tutorials and published the app at amimobenja.pythonanywhere.com/rango/ however it is not working as expected.

Check out the site and review the whole whole code at https://github.com/amimobenja/tango_with_django and recommend any necessary changes. 

--
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+unsubscribe@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/4c9c4d03-f868-4d3b-abc7-0fecddd7dd90%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Email Templates and the full website URL

I had the same problem.  Wrote this:

def get_web_server_base_url(request, settings_override_name=None):
    # Allow the value in the settings file to override any computed value.
    url = None
    if settings_override_name:
        url = getattr(settings, settings_override_name, None)
    if not url:
        protocol = request.is_secure() and 'https' or 'http'
        host = request.get_host()
        url = "{0}://{1}".format(protocol, host)
    return url

I didn't know about Site or RequestSite at the time.  Perhaps I could
have used them, but:

1. I wanted the protocol (http, or https) to be correct also.  Would
    RequestSite have done that for me?

2. I wanted to be able to override the hostname with the primary
    name of the server (via an entry in settings.py) even if the request
    was sent to a secondary name or the IP address of the server.
    I suppose Site would have allowed this, via storing the name in
    the DB, but that seems like more work than a settings.py file,
    especially since I already have convenient mechanism to manage
    different settings.py files when deployed on different servers.

Thoughts?

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

On 11/29/13 6:09 AM, Vibhu Rishi wrote:
Thanks for the links. I had done the google searches and gone through them, but they seemed to me a lot of work to get something simple.

I finally did the following. Any comments welcome if this is not a good way to do.

In my view, I pass a context object of the request to the email template. I need the request as i also want to put in the user's name.

in the email template now I changed it to :
<A href="http://{{request.get_get_host}}{% url "project.views.details" project.id %}">{{ project }}</a>

This seems to be working and quite simple too !

Regards,
Vibhu




On Fri, Nov 29, 2013 at 4:26 PM, Rafael E. Ferrero <rafael.ferrero@gmail.com> wrote:


2013/11/29 Vibhu Rishi <vibhu.rishi@gmail.com>
hi,

I have a setup where I have a project details page, and I can do a "send email" which should send the email with the URL.

Email is working fine.

The problem is that i am getting a relative url in the tempalte

I have the following in the html email template :
<A href="{% url "project.views.details" project.id %}">{{ project }}</a>

This give me a URL in the email as /projects/1 ( 1 being the project id)

How do i prepend the url of the server here ? e.g. I want this to be http://localhost:8000/projects/1

Vibhu

--
Simplicity is the ultimate sophistication. - Leonardo da Vinci
Life is really simple, but we insist on making it complicated. - Confucius
--
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+unsubscribe@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/CAPiONwn6cHwi51fJ63oFUOLof2QmFqsSeqz2VeOM_Jxk%2BaUYGQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Rafael E. Ferrero
--
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+unsubscribe@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_8WWUyfwYd1cjxNzvm0xe5LjUTNDjPGDnYaaxE9w3B1C-g%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Simplicity is the ultimate sophistication. - Leonardo da Vinci
Life is really simple, but we insist on making it complicated. - Confucius
--
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+unsubscribe@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/CAPiONw%3D7Uh9uReNyCCzhGb%3D09WHCzY9rSPp9mYn_eJRsHwmNpw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: How to get the class name of a ContentType in django

You can use type() on your instance(s) to find out their model class.

If you have an instance of the model:

stream = StreamItem.objects.create(user,ct,oid,pdate)

Then type(stream) should return <class 'StreamItem'>

Is that what you wanted?





On Sat, Nov 30, 2013 at 1:14 AM, Simon Charette <charette.s@gmail.com> wrote:
> Do you want to retrieve the class name of the model class associated with a
> content type?
>
> Le jeudi 28 novembre 2013 12:04:34 UTC-5, Aamu Padi a écrit :
>>
>> How do I get the class name in string of a ContentType? I tried it this
>> way, but it didn't worked out:
>>
>> class StreamItem(models.Model):
>> user = models.ForeignKey(User)
>> content_type = models.ForeignKey(ContentType)
>> object_id = models.PositiveIntegerField()
>> pub_date = models.DateTimeField(default=datetime.now)
>>
>> content_object = generic.GenericForeignKey('content_type',
>> 'object_id')
>> content_class = content_type.__name__
>>
>> def __unicode__(self):
>> return self.content_class
>>
>> Any help will be much appreciated! 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+unsubscribe@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/46096fde-2754-49aa-af03-3829a5d1be45%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

--
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+unsubscribe@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%2B%3DOU3XfRZy7XmTwof5QkNB3oe%2BhF0PVJO_XW8SWi9QdxqnFRg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: How to get the class name of a ContentType in django

Yes. Could you kindly please show me how?


On Sat, Nov 30, 2013 at 8:44 AM, Simon Charette <charette.s@gmail.com> wrote:
Do you want to retrieve the class name of the model class associated with a content type?

Le jeudi 28 novembre 2013 12:04:34 UTC-5, Aamu Padi a écrit :
How do I get the class name in string of a ContentType? I tried it this way, but it didn't worked out:

class StreamItem(models.Model):
    user = models.ForeignKey(User)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    pub_date = models.DateTimeField(default=datetime.now)

    content_object = generic.GenericForeignKey('content_type', 'object_id')
    content_class = content_type.__name__

    def __unicode__(self):
        return self.content_class

Any help will be much appreciated! 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+unsubscribe@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/46096fde-2754-49aa-af03-3829a5d1be45%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAHSNPWuYzjcqqzfrocSzWUoTBG%2BkuhSjk2f%2BRUk%3DMv0U1HAubg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Friday, November 29, 2013

Re: How to get the class name of a ContentType in django

Do you want to retrieve the class name of the model class associated with a content type?

Le jeudi 28 novembre 2013 12:04:34 UTC-5, Aamu Padi a écrit :
How do I get the class name in string of a ContentType? I tried it this way, but it didn't worked out:

class StreamItem(models.Model):
    user = models.ForeignKey(User)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    pub_date = models.DateTimeField(default=datetime.now)

    content_object = generic.GenericForeignKey('content_type', 'object_id')
    content_class = content_type.__name__

    def __unicode__(self):
        return self.content_class

Any help will be much appreciated! 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+unsubscribe@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/46096fde-2754-49aa-af03-3829a5d1be45%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Difference between signals and celery

Signals are like events, for example, when the ORM has done an update. Celery is more like a Task queue, you define code to execute certain task, load it on celery task server which is running separately from your django process, then when you need to execute it in the background you tell it, which usually means sending a message through a broker such as redis or rabbitmq to the task server, then it gets executed.

Celery is for background tasks, such as processing images, doing updates without blocking the main function return, etc. Also celery task can run in another machine, while signals are executed locally.

Regards,
Carlos Ruvalcaba


On Fri, Nov 29, 2013 at 11:52 AM, Robin Lery <robinlery@gmail.com> wrote:

This may be a lame question, but I am really confused with these two. I know signals are used to do some task when something has happened. But what about celery? In the documentation it says:

Celery is an asynchronous task queue/job queue based on distributed message passing.

Will someone please explain to me of what celery is? What's the difference between these two and when to use them? Will be much appreciated! 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+unsubscribe@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/62298d12-02ab-4d34-b8f7-2c4c9bace561%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAEF3qbkT2tzvHUcqLsTbg_gxY-%2BtdFinn%2BER5F-PdEf_QV-zHg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Difference between signals and celery

The easiest answer I could give is that django signals are like hooks. Something you wish to preform AFTER or BEFORE some model action. Like you wish to adjust account balance on model save. Than you would use post_save builtin django signal.

Celery is here to handle task in background. Like you wish to process some sort of upload but you want to queue it up against some broker such as rabbitmq, redis, etc. On this way you can optimize stuff and return back user faster response saying "hey, process is backgrounded. Will notify you once it's completed". Than when task finishes you can call callback and let user know as example. Consider this. You have 100000 users uploading video. That video would go into celery task so that you can scale it up properly and distribute against network + make UX appropriate. 

Hope this makes sense.

All best,
Nevio

--
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+unsubscribe@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/CAD1DFf1nLW4GnBCBdNKnLmu22kB79-q8xf7JmMbVVkaidbCnhg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Difference between signals and celery

This may be a lame question, but I am really confused with these two. I know signals are used to do some task when something has happened. But what about celery? In the documentation it says:

Celery is an asynchronous task queue/job queue based on distributed message passing.

Will someone please explain to me of what celery is? What's the difference between these two and when to use them? Will be much appreciated! 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+unsubscribe@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/62298d12-02ab-4d34-b8f7-2c4c9bace561%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

python virtual environment



Hello

I am trying to run a project that was setup in another server, but getting the following error. I am using python 2.7, django, virtualenv. So I am running the project inside a python virtual environment


(virtualenv)[web.srv1 daily# python manage.py runserver 0.0.0.0:8000
Traceback (most recent call last):
  File "manage.py", line 2, in <module>
    from django.core.management import execute_manager
ImportError: cannot import name execute_manager


I used the method mentioned in the below link to setup the virtual environment.

http://toic.org/blog/2011/wsgi-on-cpanel-improved/

This project was setup inside a cpanel server. But the current server I using is not a cpanel server. It is normal centos server.

Can somebody help me to track down the issue.


--
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+unsubscribe@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/7181ba64-d2d6-4926-b35d-5b4a2a7792a4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: multi-table inheritance newbie

On Fri, 29 Nov 2013 07:34:47 -0800 (PST), TW <terry433iid@googlemail.com>
declaimed the following:

>I'm using multi-table inheritance in project and need some help geeting my
>mind around this concept
>
>I have parent class 'test' which is a machine test (members : name, version
>state; methods : add_test, remove_test)
>
>I now create a child class 'result' which inherits from parent class 'test'
>- 'result' is the result of all the scenarios inside the machine test
>(multiple scenarios per machine test)
>
>Child class 'result' will have its own members/methods (members :
>scenario_name, scenario_outsome; methods : add_result, delete_result)
>
>So now I can create an instance of parent 'test' class by calling the child
>class 'result'
> >>>>testme= result.add_test("""args""")
>
>So what is now in the object "testme" that I just created? I cannot
>viasualise what this instance holds and how the parent/child relationship
>works
>
>What would be some useful method calls be to help me get a better
>understanding of the 'result' object so I could 'see' the influence of the
>'parent' class inheritance
>
>thanks


Normally I'd trim the quote, but there are too many concepts floating
around in the above...

My first impression is that you are using the wrong mechanism... You
probably want a one-to-many relationship between two otherwise independent
tables:

TEST(_ID_, name, version, state)
RESULT(_ID_, *testID*, name, outcome)

in which _ID_ is the table primary key (Django handles those behind the
scenes as I recall), and *testID* is a foreign key linking that RESULT row
to the corresponding TEST description. Multiple "scenarios" in one "test"
means multiple RESULT rows all having the same testID value.

Inheritance, as normally considered in OOAD, implies an extension from
the base class...

VEHICLE(_ID_, maker, model, serialnumber)
CAR[VEHICLE](engine, transmission, tiresize, exteriorcolor, interiorcolor,
audio)
JETLINER[VEHICLE](engine, firstclassSeats, businessclassSeats, coachSeats)

Both CAR and JETLINER inherit _ID_, maker, model, serialnumber from
VEHICLE.

https://docs.djangoproject.com/en/1.4/topics/db/examples/many_to_one/

instead of

https://docs.djangoproject.com/en/1.4/topics/db/models/#model-inheritance

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

--
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+unsubscribe@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/k5hh99lf7341nauigebit43pe4qfjl5jfm%404ax.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Signals not working as expected

Ok, thank you all!


On Fri, Nov 29, 2013 at 9:56 PM, Robin Lery <robinlery@gmail.com> wrote:
Yes.


On Fri, Nov 29, 2013 at 9:55 PM, Robin Lery <robinlery@gmail.com> wrote:
Do i put the codes to all the app's -  models.py?


On Fri, Nov 29, 2013 at 9:44 PM, Tom Evans <tevans.uk@googlemail.com> wrote:
On Fri, Nov 29, 2013 at 4:06 PM, Aamu Padi <aamupadi@gmail.com> wrote:
> Thank you for the answer. I am a newbie, would be very grateful if you could
> please show me how to do that?

Put the code in signals.py at the bottom of models.py and delete signals.py

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+unsubscribe@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/CAFHbX1%2Bz_MYkfWvmDG1PvuY%3Doy7OG%2BJvK9xmq_PNh%3DprpUhwxA%40mail.gmail.com.



--
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+unsubscribe@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%2B4-nGrdhogxd3DBgC2ZeebQFHsqQfex5PogRFdeKA0KGBN10g%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Signals not working as expected

Yes.


On Fri, Nov 29, 2013 at 9:55 PM, Robin Lery <robinlery@gmail.com> wrote:
Do i put the codes to all the app's -  models.py?


On Fri, Nov 29, 2013 at 9:44 PM, Tom Evans <tevans.uk@googlemail.com> wrote:
On Fri, Nov 29, 2013 at 4:06 PM, Aamu Padi <aamupadi@gmail.com> wrote:
> Thank you for the answer. I am a newbie, would be very grateful if you could
> please show me how to do that?

Put the code in signals.py at the bottom of models.py and delete signals.py

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+unsubscribe@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/CAFHbX1%2Bz_MYkfWvmDG1PvuY%3Doy7OG%2BJvK9xmq_PNh%3DprpUhwxA%40mail.gmail.com.


--
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+unsubscribe@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%2B4-nGpQ5TMu6rRrCfE%2BL5y%2Bj3QciZR9NjeBwajh1mJMkswxXA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Signals not working as expected

Do i put the codes to all the app's -  models.py?


On Fri, Nov 29, 2013 at 9:44 PM, Tom Evans <tevans.uk@googlemail.com> wrote:
On Fri, Nov 29, 2013 at 4:06 PM, Aamu Padi <aamupadi@gmail.com> wrote:
> Thank you for the answer. I am a newbie, would be very grateful if you could
> please show me how to do that?

Put the code in signals.py at the bottom of models.py and delete signals.py

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+unsubscribe@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/CAFHbX1%2Bz_MYkfWvmDG1PvuY%3Doy7OG%2BJvK9xmq_PNh%3DprpUhwxA%40mail.gmail.com.

--
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+unsubscribe@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%2B4-nGqvJuwuC%2Ba7HM2EsKdfUQiS4DDikrmYUXHZeh%2BfJKOG3g%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Signals not working as expected

On Fri, Nov 29, 2013 at 4:06 PM, Aamu Padi <aamupadi@gmail.com> wrote:
> Thank you for the answer. I am a newbie, would be very grateful if you could
> please show me how to do that?

Put the code in signals.py at the bottom of models.py and delete signals.py

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+unsubscribe@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/CAFHbX1%2Bz_MYkfWvmDG1PvuY%3Doy7OG%2BJvK9xmq_PNh%3DprpUhwxA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Signals not working as expected

Thank you for the answer. I am a newbie, would be very grateful if you could please show me how to do that?


On Fri, Nov 29, 2013 at 9:28 PM, Jérôme Thiard <jerome.thiard@gmail.com> wrote:

You can put signal handling and registration code anywhere you like. However, you'll need to make sure that the module it's in gets imported early on so that the signal handling gets registered before any signals need to be sent. This makes your app's models.py a good place to put registration of signal handlers.

 I think you have to put your connection code in models.py (your `create_stream_item` function can still live in signals.py) in order to be sure connections are made early enough.

2013/11/28 Aamu Padi <aamupadi@gmail.com>
I am trying to create a project for creating feeds/activity feeds of a user with the help of a blog.

These are the models -

    class StreamItem(models.Model):
        user = models.ForeignKey(User)
         content_type = models.ForeignKey(ContentType)
        object_id = models.PositiveIntegerField()
        pub_date = models.DateTimeField(default=datetime.now)
        content_object = generic.GenericForeignKey('content_type', 'object_id')

        @property
        def content_class(self):
            return self.content_type.model


    class Blog(models.Model):
        user = models.ForeignKey(User)
        title = models.CharField(max_length=300)
        body = models.TextField()
        pub_date = models.DateTimeField(default=datetime.now)
   
   
    class Photo(models.Model):
        user = models.ForeignKey(User)
        title = models.CharField(max_length=200)
        image = models.ImageField(upload_to=get_upload_file_name)
         pub_date = models.DateTimeField(default=datetime.now)

And this is the signals.py:

    from django.db.models import signals
    from django.contrib.contenttypes.models import ContentType
    from django.dispatch import dispatcher
    from blogs.models import Blog
    from picture.models import Photo
    from models import StreamItem

    def create_stream_item(sender, instance, signal, *args, **kwargs):

         # Check to see if the object was just created for the first time

        if 'created' in kwargs:
             if kwargs['created']:
                 create = True

                 # Get the instance's content type

                 ctype = ContentType.object.get_for_model(instance)

                 if create:
                     si = StreamItem.objects.get_or_create(content_type=ctype, object_id=instance.id, pub_date = instance.pub_date)

     # Send a signal on post_save for each of these models

    for modelname in [Blog, Photo]:
        dispatcher.connect(create_stream_item, signal=signals.post_save, sender=modelname)

When I create a blog or upload a photo, the `signal` does not work. But I can manually add items to the `StreamItem` app using the admin, and the StreamItem does work as I want it to be. I think there's problem with the signals.py. Please help me out. Would be much appreciate. 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+unsubscribe@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/CAHSNPWtGQPpE7eexnis6EpC2-_WtLcf0ZY-uhvuschj7Tg3MVA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAOLVUFdryq%3DpKvx6Jm6brPHwfbDOetcJQVgo92dEUDjUhQLiKQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAHSNPWsUCVqY0ZYPYSYRO%3DXSicAj5E0n16BeNf9iZM%3D3%3D7ar9w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.