Make sure you don't push db files (files with .sqlite
, .db3
, etc. extension).
This is a required for the tests to pass.
Good example:
additional_data = data["info"] if data["info"] else None
Model.objects.create(
field=additional_data
)
Normal example:
Model.objects.create(
field=(data["info"] if data["info"] else None)
)
Bad example:
Model.objects.create(
field=None
) if data["info"] is None else Model.objects.create(
field=data["info"]
)
The context manager is needed to work with the file, in our case, to read data. Therefore, after you have read the data from the file, exit the block.
Good example:
with open("file.json") as file:
data = json.load(file)
# do something outside of the context manager
Bad example:
with open("file.json") as file:
data = json.load(file)
# do something inside of the context manager
-
Use
on_delete=models.CASCADE
if you know that some model doesn't exist without other model. So when the referenced object is deleted, also delete the objects that have references to it. -
Use
on_delete=models.SET_NULL
if you know that the object should not be deleted, even if the object it references may be deleted.
-
When you use
auto_now_add
- it records the time and date of creation. -
When you use
auto_now
- updates the value of the field to the current time and date every time when the object changes.