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
0
votes
1 answer

After Model and many to many fields saved signal django

I have models like class Genre(models.Model): name = models.CharField(max_length=50) class Cast(models.Model): name = models.CharField(max_length=120, null=False, blank=False) class movie: name = models.CharField(max_length=120,…
Ebrahim Karimi
  • 732
  • 8
  • 24
0
votes
0 answers

Determine signal in receiver

I need to create Redirect object when page with certain attribute gets either removed or set disabled, so what it's saved I need to determine if it's disabled, or if it's deleted I need to create this Redirect anyway. @receiver([post_save,…
Dmitrii Mikhailov
  • 5,053
  • 7
  • 43
  • 69
0
votes
0 answers

Get userID in django.dispatch.receiver

I am trying to use the ID of the django user for an action when a model is saved. For that I have a receiver as follows: @receiver(post_save, sender=ServersModel) def create_zabbix_host(sender, instance=None, created=False, **kwargs): if…
Kheshav Sewnundun
  • 1,236
  • 15
  • 37
0
votes
2 answers

How to save related model instances before the model instance in django?

How to save the related model instances before the instance model. This is necessary because I want to preprocess the related model's instance field under model instance save method. I am working on Django project, and I am in a situation, that I…
shining
  • 1,049
  • 16
  • 31
0
votes
0 answers

How to save the django model after its many to many field and foreign key saved

I am working on a Django project, which has a number of fields including many ForeignKey and ManyToMany Fields. and I am trying to create a flat json file by serializing this model so that I can index it into an elastic search server by using…
shining
  • 1,049
  • 16
  • 31
0
votes
1 answer

Django - Multiple post_save signals after create despite dispatch_uid

I'm having trouble preventing a post_save signal from firing multiple times after the creation of an object. My signal is defined as follows: @receiver(post_save, sender=Order, dispatch_uid='post_save_order') def post_save_order(sender, **kwargs): …
user2817219
  • 322
  • 1
  • 4
  • 13
0
votes
1 answer

django-registration creating blank django-profiles using signals

I have gone through the solution here and Shacker's django-profiles: The Missing Manual and subsequent signals solution by Dmitko and answers here and many places. Here are the details: AUTH_PROFILE_MODULE = "members.Profile" From…
0
votes
1 answer

How to receive Django post_save signal on AJAX query?

I use AJAX request to create an order, also I have a post_save signal that should be executed after the order will save. Whether is it possible to receive this post_save signal on an AJAX request?.. because I don't get aything, the signal handler is…
Yurii Rabeshko
  • 591
  • 8
  • 17
0
votes
2 answers

User Object in Django Signals

I am using .post_save in some of my models to do some time consuming works. I want to track which user is actually sending the signals. Is there any way to do that?
0
votes
1 answer

Django Signals stops listening after about 2 calls

So I have the following signal set up post_save.connect(self.increment_on, sender=self.model_dict[self.model_involved], dispatch_uid='increment_for' + …
Vincent Buscarello
  • 395
  • 2
  • 7
  • 19
0
votes
1 answer

Maintaining Relationships Between Models that are Filled Through Signals After Saving

Look at answers to see how I solved it and what my problem was :) I have a base model called stars that contains most relationships with other models, and some of the other models are taken through a signal to perform certain scripts that will…
Giannina
  • 43
  • 7
0
votes
1 answer

Is it "better" to have an update field or COUNT query?

In a Django App I'm working on I've got this going on: class Parent(models.Model): name = models.CharField(...) def num_children(self): return Children.objects.filter(parent=self).count() def avg_child_rating(self): …
0
votes
1 answer

Should I prefer one general signal instead of multiple specific ones?

When the user creates a product, multiple actions have to be done in save() method before calling super(Product,self).save(*args,**kwargs). I'm not sure if I should use just one pre_save signal to do all these actions or it is better to create a…
Milano
  • 18,048
  • 37
  • 153
  • 353
0
votes
0 answers

Getting list of many to many objects

class Team(models.Model): team_name = models.CharField(max_length=50, null=False) def __str__(self): return self.team_name class Tournament(models.Model): types = ( ('Round', 'Round'), ('Knockout',…
cnian
  • 239
  • 4
  • 18
0
votes
1 answer

Why does cached_property always update the data?

There is a model, in its geoposition field, latitude and longitude are stored, as a string, in this form '27 .234234234,53.23423423434'. This field is provided by django-geoposition. Thanks to him it is very convenient to enter the address. I also…
Narnik Gamarnik
  • 1,049
  • 1
  • 16
  • 35