Skip to content

Conversation

@Sin93
Copy link
Owner

@Sin93 Sin93 commented Apr 1, 2021

Извиняюсь, на работе завал, на выходных сделаю и пришлю

Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Worth considering though

)

# удалять заказы пользователя если пользователь был удалён - не самая лучшая идея, по этому выставлю SET_NULL
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True)
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True
)

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up.

Expect unwanted behavior if null and blank are different values: null controls if the database allows no value for user and blank controls if the application allows no value for user. Consider setting null and blank to the same value for user.


class OrderItem(models.Model):
order = models.ForeignKey(Order, related_name="order_items", on_delete=models.CASCADE)
product = models.ForeignKey(Product, verbose_name='продукт', on_delete=models.CASCADE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, with an explicit related_name would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants