I have a python file that creates objects with this method Category.objects.create. But I don’t know how to run that fixture
I have a python file that creates objects with this method Category.objects.create. But I
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Fixtures are serialized. Python code that populates the database is not a fixture.
If you want to populate the database with python code after the it has been created, I suggest you attach your creation function to the
post_syncdbsignal. Note that the signal is sent per application.In your callback function, you can check the
created_signalsparameter, to see which models were created, and check whether you need to create the objects.As a reference, have a look at the contrib apps that use the
post_syncdbsignal, for exampledjango.contrib.sites.manage, which creates the default site instance only once.