Questions tagged [django-signals]

Django signals allow listeners to be registered for events within the framework. This allows decoupled handling of, for example, model deletions.

Django signals allow listeners to be registered for events within the framework. This allows decoupled handling of, for example, model deletions.

Quote from docs:

Django includes a “signal dispatcher” which helps allow decoupled applications get notified when actions occur elsewhere in the framework. In a nutshell, signals allow certain senders to notify a set of receivers that some action has taken place. They’re especially useful when many pieces of code may be interested in the same events.

See documentation.

877 questions
-1
votes
1 answer

Django Error: 'RelatedManager' object has no attribute 'save'

This is my model: class Stock_Total(models.Model): purchases = models.ForeignKey(Purchase,on_delete=models.CASCADE,null=True,blank=True,related_name='purchasetotal') stockitem =…
Niladry Kar
  • 1,163
  • 4
  • 20
  • 50
-1
votes
1 answer

Testcases for SIgnals Django

Hi I have been trying to write the test case for the following post save signal, without any success. Can anyone help. @receiver(post_save, sender=Item, dispatch_uid="item_created") def notify_member_item_create(sender, instance, **kwargs): …
-1
votes
1 answer

Setting variables with Django signals without using globals

In Django 1.9 I construct a list of forms based on a database table corresponding to TheModel in my forms.py. When the database table changes I want the forms to change as well. Therefore I set up a Django signal to listen to the change and update…
Jarno
  • 6,243
  • 3
  • 42
  • 57
-1
votes
1 answer

Update other fields during the save

I have declared a signal for the UserProfile model which updates some other fields. The stored data are coming from a web service. post_save.connect(user_profile_update, sender=UserProfile) in user_profile_update, i did this: profile =…
cem
  • 1,535
  • 19
  • 25
-2
votes
0 answers

Django: signal doesn't work well with ForeignKey

models.py from django.db import models class Post(models.Model): text = models.TextField() approved = models.BooleanField(default=False) group = models.ForeignKey('bot_users.BotUserGroup', on_delete=models.SET_NULL, null=True,…
-2
votes
2 answers

How do I use Signals i Django to Calculate Age based on Date entered, if entered at all?

We do not use Date of Birth as a mandatory field during signup. But, in the Model we have an auto-calculate function to arrive at the 'Age' of the user. So while this works fine when using Django built-in registration mechanism, it fails with…
-3
votes
1 answer

Django. Related model returns None after primary model save

I have two models: Item and Photo. Item is foreignkey to Photo so one item can have many photos connected which is quite usual. Item class: class Item(models.Model): name = models.CharField('Item Name', max_length = 150, null = False, …
Hazaard
  • 3
  • 4
1 2 3
58
59