use python instead on django shell

I have a basic project called airline with one app called flights. I create one model called Flight.

in a file called test.py I have:

from flights.models import Flight

f= Flight(origin=“New York”,destination=“London”, duration = 415)
f.save()

where do I place this file in order to run and update the database table? makemigrations and migrate were run successfully. Is there anything else that needs to be done to make the code run?

If you’re looking to run Python scripts in the “Django Context” (accessing models, etc), I suggest you take a look at the Writing custom django-admin commands docs. If you’re just looking to preload data into tables, take a look at the docs for Providing initial data for models.

1 Like