Query Regarding Django Signals

23 views
Skip to first unread message

Nipun Arora

unread,
May 4, 2018, 12:10:12 PM5/4/18
to Django users
Hello Community 

I was puzzled by the fact that if django signals are not asynchronous why do we use them as in when ever i want some trigger on post_save can't  i simply write that particular trigger in the same function that handles the request for saving a new object in django views..?
as in :


def handlerequest(Request):
    save instance to db 
   Do the work i would do in the method handling the signal post_save


Matthew Pava

unread,
May 4, 2018, 12:28:03 PM5/4/18
to django...@googlegroups.com

The advantage with the signals is that you can put all that code in one place.  You may have different views that are saving the same model, and it isn’t DRY to have to put that same code in multiple locations.

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5b64f4e4-afa2-485b-96a9-825b3c93b95e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jani Tiainen

unread,
May 4, 2018, 4:14:21 PM5/4/18
to django...@googlegroups.com
Hi,

Signals are also good for decoupling things.

For example you want to do some post save action for third party models.

jacob duyon

unread,
May 4, 2018, 4:16:15 PM5/4/18
to django...@googlegroups.com
You can also just write a Celery task to do your async stuff and trigger it from signals.py

On Fri, May 4, 2018 at 4:13 PM, Jani Tiainen <red...@gmail.com> wrote:
Hi,

Signals are also good for decoupling things.

For example you want to do some post save action for third party models.
4.5.2018 19.10 "Nipun Arora" <aroran...@gmail.com> kirjoitti:
Hello Community 

I was puzzled by the fact that if django signals are not asynchronous why do we use them as in when ever i want some trigger on post_save can't  i simply write that particular trigger in the same function that handles the request for saving a new object in django views..?
as in :


def handlerequest(Request):
    save instance to db 
   Do the work i would do in the method handling the signal post_save


--
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.

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Nipun Arora

unread,
May 5, 2018, 2:25:24 AM5/5/18
to Django users
okay thanks people..!

Ruhia gr

unread,
May 5, 2018, 1:37:11 PM5/5/18
to django...@googlegroups.com
hello everyone m new to django and am starting my ecommerce project in djnago .please anyone suggest which is best for ecommerce project(online shopping)django or django cms

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages