All within the Django admin , I'd like to enter form fields related to generating a report. Fields you'd expect in a report: report name, report type, start and end dates, report fields, etc.
How would one take these inputs, grab the inputs from the request, pass these inputs to an API (in the background), then process it (in queue-like fashion), finally create a CSV or PDF to download?
I'm fine with creating the admin model form and I think grabbing the inputs when the form is submitted in the admin, then I think I simply pass those inputs to my other API code to process...
My questions are:
/change/
page? Is there best-practice for this? I haven't been able to find an example of this when dealing with the admin. I'm not new to Python but am somewhat new to Django.
Nobody will likely answer. Therefore, I'll share my high-level general solution.
celery.py
and modify your __init__.py
like it shows in celery's documentation. The key "gotcha" is where they put "proj", you should put the actual name of your project, not "proj". admin.ModelAdmin
class, override save_model(self, request, obj, form, change)
to capture the form data submitted from the admin form. tasks.py
within the current app. Ex: get_report.delay(name, start, end, type)
. Note the .delay part as this is what allows it to run in the background without having to wait at the screen after you submit the form. save_model(...)
, you still have to call super().save_model(request, obj, form, change)
at the end. celery -A scorecard worker --pool=solo -l info
(to start the worker - you type this in Terminal), OR, you can install eventlet and use eventlet as the --pool=eventlet
value instead of --pool=solo
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.