1👍
@receiver(post_save, sender=MyModel)
@receiver(post_save, sender=AnotherModel)
def generate_smth(sender, instance, created, **kwargs):
if sender.__name__ = 'MyModel':
# Bar
else:
# Foo
0👍
Do you want both functions to have the same behaviour? If yes, you can do:
def do_smth(sender, instance, created, **kwargs):
...
@receiver(post_save, sender=MyModel)
def generate_smth(sender, instance, created, **kwargs):
do_smth(sender, instance, created, **kwargs)
@receiver(post_save, sender=AnotherModel)
def generate_another_smth(sender, instance, created, **kwargs):
do_smth(sender, instance, created, **kwargs)
- [Answer]-Django CreateView does not save object
- [Answer]-Inserting a foreign field in django forms
- [Answer]-Return in Http Response and Html page but its not showing on the browser in Django
- [Answer]-Is Django's localflavor.ca.ca_provinces.PROVINCE_CHOICES right?
- [Answer]-Django OneToOneField deleting child doesn't set parents parameter as None?
Source:stackexchange.com