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
0 answers

Django Signal that provides access to response of a request?

So far in our code we have implemented Django built-in signals for handling user login, logout, and failed login as well as db actions with pre-save, post_save and post_delete signals. I am looking to maintain consistency by performing some…
0
votes
2 answers

django post_save: update_or_create not working

class SubjectSectionTeacher(models.Model): Education_Levels = models.ForeignKey(EducationLevel, related_name='+', on_delete=models.CASCADE, blank=True) Courses = models.ForeignKey(Course, related_name='+', on_delete=models.CASCADE,…
user12324446
0
votes
1 answer

My signals stopped working after extending my default user model using BaseUserAdmin

I had a working signal that creates a new profile when a new user is created, but i wanted to extend the users as either teacher, parent, or Admin, then it stopped working. Models.py from django.db import models from django.contrib.auth.models…
0
votes
0 answers

Django populating model in signal with accessing request

I am in trouble in populating a table, at first see my models. from django.contrib.auth.models import User class Group(models.Model): members = models.ManyToManyField( User, through='PersonGroup', …
user12196679
0
votes
0 answers

Django geting request in signal post_save

I am trying to access Django built-in request to get some important data and most of them coming through my custom middleware, that is why i need to access the request at any means. this is my signal: @receiver(post_save, sender=MyModel) def…
user12196188
0
votes
1 answer

How to link a profile to a newly created user using Django

Just finished a website using Django and i got stuck after creating a user or superuser. For some reason the same code i used before does not work anymore, and now whenever i create a new user it is saved (because i cant create another one with the…
Claudiu Remenyi
  • 75
  • 1
  • 1
  • 6
0
votes
1 answer

Update django task when model field is changed

I have a django model which contains details of when a particular task (email reminder) should be run for a particular booking. It looks a bit like this:- class Task(models.Model): PENDING = 'pending' IN_PROGRESS = 'in_progress' COMPLETE…
bodger
  • 1,112
  • 6
  • 24
0
votes
1 answer

Issue with connecting django signals

I am trying to set up a History table that uses django signals in it in order to build a dashboard. Inside my history models.py I have: from django.dispatch import dispatcher from django.db.models import signals from project.models import…
TheLifeOfSteve
  • 3,208
  • 6
  • 37
  • 53
0
votes
1 answer

django - setting a non-nullable field in pre_save

I'm trying to set a non nullable OneToOneField object (which hasn't been set) in the pre_save method. class A(Model): b = models.OneToOneField(B, on_delete=CASCADE) @staticmethod def pre_save(sender, instance, **kwargs): try: …
Martin Massera
  • 1,718
  • 1
  • 21
  • 47
0
votes
0 answers

Django save aggregation in master/detail (many to one relationship)?

I have two models, Order and OrderRow (1:n). What I would like is when something changes on the OrderRow (added, removed, price change, etc.) that that "effect" is calculated to the parent Order. In this case, sum the total of all the OrderRow in…
Roger
  • 7,535
  • 5
  • 41
  • 63
0
votes
1 answer

Where in Django code put code disconnecting signal and doing monkey-patching?

I'm working on custom authorization backend for Django 2.2. I don't want django to update last_login for user so I wanted to disconnect signal user_logged_in from triggering update_last_login. I also have to do monkey patch in SimpleJWT library…
0
votes
1 answer

Create M2M Relationship in post_save Signal from Admin

What is the proper way to create M2M relationships during a post-save signal in the admin panel? I have the below code. It successfully creates two Articles and a Blog but does not save the relationship between the two. ## models.py from django.db…
Ben J.
  • 766
  • 1
  • 6
  • 17
0
votes
0 answers

How to autocreate a User from a model extending it in Django models

I am creating members for an application in Mezzanine and I need to add them via the admin and extend User model. How can I auto-create a user from Member model I am using mezzanine and Django and I have tried using Abstractuser but mezzanine throws…
0
votes
0 answers

How to get user in Django signals

How can you get the user who is saving record in django signals? I am using signals to fill in data when a user marks completed = True via a form. I was hoping something like instance.User or instance.CustomUser.username would work, but it just…
MattG
  • 1,682
  • 5
  • 25
  • 45
0
votes
1 answer

AttributeError: module 'asyncio' has no attribute '_get_running_loop'

I am using channels to implement WebSockets. I am trying to send data through websocket from post_save django signal. Below is my code. signals.py @receiver(post_save, sender=CheckIn) def send_data_on_save(sender, instance, **kwargs): …