Make sure you don't push db files (files with .sqlite
, .db3
, etc. extension).
This is a required for the tests to pass.
Call the save()
method only one time if it's possible.
Good example:
user = get_user_model().objects.create_user(
username=username, password=password
)
if first_condition:
# some actions
if second_condition:
# some actions
user.save()
Bad example:
user = get_user_model().objects.create_user(
username=username, password=password
)
if first_condition:
# some actions
user.save()
if second_condition:
# some actions
user.save()
- Use one style of quotes in your code. Double quotes are preferable.
- Implement
class Meta
only after you defined all attributes.
Good example:
class Order(models.Model):
created_at = ...
user = ...
class Meta:
pass
Bad example:
class Order(models.Model):
created_at = ...
class Meta:
pass
user = ...
- Choose correct and suitable variable names.
Good example:
user = get_user_model().objects.create_user(
username=username, password=password
)
Bad example:
u = User.objects.create_user(
username=username, password=password
)
- Use
get_user_model()
instead ofUser
, it is the best practice.
Good example:
get_user_model().objects.create_user(
username=username, password=password
)
Bad example:
User.objects.create_user(
username=username, password=password
)
Add comments, prints, and functions to check your solution when you write your code. Don't forget to delete them when you are ready to commit and push your code.