1๐
Iโm not a big fan of class based views, I prefer fat models and thin views.
I would opt for an post_save signal on Request and check the created param.
https://docs.djangoproject.com/en/dev/ref/signals/#post-save
Request(...):
@classmethod
def post_save(cls, sender, instance, created, raw, **kwargs):
if raw:
return
if created:
pass # do your on create stuff here
post_save.connect(Request.post_save, sender=Request, dispatch_uid="uniqueid") # use weak=False if you use a local function
Also note that instance.save() triggers the save signals again, so you might consider to just use .update() if you want to avoid all your signals to be processed again (or even worse, create a signal loop ๐ )
๐คACimander
Source:stackexchange.com