You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-res...@googlegroups.com
I've setup a working REST API following the docs and everything is working great. Now I'd like to kick off a custom task when I POST certain fields into my CurrentTask Model. Here is the model:
It should kick off some custom Python to run when I post into the run_id field, and a run_config field. Those parameters are then passed into my custom code, then the code will update the model during the course of its function finally ending with a filling out the success fields, and result_code fields. What is the best way to approach this? It's kinda hard to google since I don't know if I'm using the right language. Hopefully this post makes sense, if there's another approach to this particular workflow, I'm happy to change it.
Thanks, Adam
Tim Watts
unread,
Feb 20, 2014, 8:31:56 PM2/20/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-res...@googlegroups.com
Hi Tim,
Thanks for the options you pointed out. The more I look at this use case, the more celery looks like the right solution. Until then I'll try the other options, starting with number 2. I'm using a class view that inherits the viewsets.ModelViewSet and I'll try overriding the create method to call my code in that function.
I have plenty to work with and will follow up with my solution for posterity.
Thanks again! Cheers!
Adam G
unread,
Feb 21, 2014, 5:52:11 PM2/21/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-res...@googlegroups.com
Overriding the create method worked like a charm. However the requirements have changed, and I no longer need to launch on POST. For what it's worth if you use a viewset that inherits from viewsets.ModelViewSet then copy the create method from the inherited mixins.CreateModelMixin and add the code there. Beware that the code will block, here's what I mean:
if serializer.is_valid(): self.pre_save(serializer.object) self.object = serializer.save(force_insert=True) self.post_save(self.object, created=True) #run code here, but it will stop everything until it runs #for example this will make django unresponsive for 100 seconds #time.sleep(100) #so maybe run your code in a thread or async process #or maybe throw a decorator over the create method that handles the async task? headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)