django-signals

Using django signals in channels consumer classes

﹥>﹥吖頭↗ 提交于 2020-08-21 00:22:46
问题 I am trying to develop an auction type system, where a customer makes an order, and then different stores can offer a price for that order. An interesting part of this system is that when the order is initially created, the available stores will have 60 seconds to make their respective offer. When a first store makes their offer, the "auction" will now only have the next 20 seconds for other stores to make their own offer. If they do make another offer, in this smaller allocated time, then

Using django signals in channels consumer classes

故事扮演 提交于 2020-08-21 00:17:08
问题 I am trying to develop an auction type system, where a customer makes an order, and then different stores can offer a price for that order. An interesting part of this system is that when the order is initially created, the available stores will have 60 seconds to make their respective offer. When a first store makes their offer, the "auction" will now only have the next 20 seconds for other stores to make their own offer. If they do make another offer, in this smaller allocated time, then

Want to disable signals in Django testing

戏子无情 提交于 2020-05-09 19:02:07
问题 So I have various signals and handlers which are sent across apps. However, when I perform tests / go into 'testing mode', I want these handlers to be disabled. Is there a Django-specific way of disabling signals/handlers when in testing mode? I can think of a very simple way (of including the handlers within an if TESTING clause) but I was wondering if there was a better way built into Django?... 回答1: No, there is not. You can easily make a conditional connection though: import sys if not

Create a GIF from Video using Django Signals and MoviePy

醉酒当歌 提交于 2020-04-18 03:48:11
问题 I wanted to apply Django's Signals to the following model: class Video(models.Model): created = models.DateTimeField(auto_now_add=True) text = models.CharField(max_length=100, blank=True) image = models.ImageField(upload_to='Images/',blank=True) video = models.FileField(upload_to='Videos/',blank=True) gif = models.FileField(upload_to = 'Videos/', blank = True) class Meta: ordering = ('created', ) The reason why I use signals: Whenever a Video object gets created, we get notified and then we

Django signals post_save update

非 Y 不嫁゛ 提交于 2020-02-26 00:53:12
问题 When the student enrollment record (discount type) is updated the student discount (discount type) is also updated, but what should i do if i want to update the student enrollment record (discount type) using student discount (discount type) This is my models.py class studentDiscount(models.Model): Students_Enrollment_Records = models.ForeignKey(StudentsEnrollmentRecord, related_name='+', on_delete=models.CASCADE, null=True) Discount_Type = models.ForeignKey(Discount, related_name='+', on

django - comparing old and new field value before saving

蹲街弑〆低调 提交于 2020-01-19 19:35:14
问题 I have a django model, and I need to compare old and new values of field BEFORE saving. I've tried the save() inheritence, and pre_save signal. It was triggered correctly, but I can't find the list of actualy changed fields and can't compare old and new values. There is a way? I need it for optimization of presave actions. Thank you! 回答1: There is very simple django way for doing it. "Memorise" the values in model init like this: def __init__(self, *args, **kwargs): super(MyClass, self)._

Getting information from Django custom signal receiver

混江龙づ霸主 提交于 2020-01-15 12:30:12
问题 This is my second question today actually but what I want to know...Is it possible to retrieve information from a signal handler. I have a list of items, call it list and each item is in AppA. Each item has a couple of characteristics which are saved in a different app, AppB. So, I figured that I could maybe create a dictionary, dict and iterate over the items in list. In each iteration, I was hoping to send a signal to AppB and retrieve the information, i.e. have something like def blob

Is it possible to selectively suppress a post_save (or other) signal in Django?

寵の児 提交于 2020-01-12 05:29:10
问题 I'm wondering whether it's possible to selectively suppress a Django signal (such as post_save or post_init ) on object creation, or, alternatively, send it certain parameters. What I have is a User object, which can be created in many different ways and places in my code. So to automatically assign a custom Profile object to each User , I use the post_save signal. However, in one specific case, there is extra information that I want to bind to the created Profile object. Passing it as

A signal m2m_changed and bug with post_remove

天大地大妈咪最大 提交于 2020-01-10 03:58:06
问题 I need to detect a post_remove signal, so I have written : def handler1(sender, instance, action, reverse, model, pk_set, **kwargs): if (action == 'post_remove'): test1() # not declared but make a bug if it works, to detect :) m2m_changed.connect(handler1, sender=Course.subscribed.through) If I change 'post_remove' by 'post_add' it is ok.. Is it a django's bug about post_remove ?? I use that model and I switch beetween two values of 'subscribed' (so one added and one deleted) class Course

How can I prevent post_save recursion in Django?

别来无恙 提交于 2020-01-10 02:58:04
问题 I have some problems when using signal in Django. post_save occurs recursion because of instance.save() inside of function. But strange thing is only one case occurs recursion. Case not occuring recursion. models.py class Product(TimeStampedModel): name = models.CharField(max_length=120) slug = models.SlugField(null=True, blank=True) description = models.CharField(max_length=400, blank=True) is_active = models.BooleanField(default=True) objects = ProductManager() class Meta: ordering = ('