Total novice here and so far, I have been working through the tutorial app on building a poll. In the poll app, it seems that one can add questions and choices only through the shell. I want to add several questions which I have in a Pandas data frame that were programmatically generated. I want to insert all those questions and make them available for voting. I see that I could write a python script and run it in the Django python shell. Is this the recommended way? Any other better options out there?
Appreciate any inputs.
Thanks in advance!
For what the tutorial provides, that is correct.
However, you do have multiple options:
Adding them through the Admin
Create your own views and forms to allow them to be entered
Create a custom django-admin command to create model instances
Write a Python script to add the data directly to the tables (outside of Django)
Create a REST interface to allow for inserting data
Take your pick…
Thank you for your response! I appreciate the options.
I thought of adding them through the admin since the questions would all be controlled by the admin (myself). However, I am not sure how to trigger the addition of the questions. Would I have to create a “POST button” on the admin page that gives a trigger to add the questions and choices? Does that sound reasonable?
I am also liking the fixtures approach. However, I am not sure what it means when the document says that the data is not loaded unless I use TransactionTestCase.fixtures?
Thanks again for your response!
To completely quote the referenced section:
You can also provide data using fixtures, however, this data isn’t loaded automatically, except if you use
The rest of that section describes using the
loaddata command to load fixtures.
That’s covered in the tutorial in part 7
Thank you so much once again! I really appreciate it!