How to use Django model inheritance with signals?

前端 未结 8 814
无人共我
无人共我 2020-12-23 11:15

I have a few model inheritance levels in Django:

class WorkAttachment(models.Model):
    \"\"\" Abstract class that holds all fields that are required in eac         


        
8条回答
  •  忘掉有多难
    2020-12-23 11:51

    You could register the connection handler without sender specified. And filter the needed models inside it.

    from django.db.models.signals import post_save
    from django.dispatch import receiver
    
    
    @receiver(post_save)
    def my_handler(sender, **kwargs):
        # Returns false if 'sender' is NOT a subclass of AbstractModel
        if not issubclass(sender, AbstractModel):
           return
        ...
    

    Ref: https://groups.google.com/d/msg/django-users/E_u9pHIkiI0/YgzA1p8XaSMJ

提交回复
热议问题