All checks were successful
Build and Push Docker Image / build (push) Successful in 51s
- Implemented `Favorite` model with unique user-item constraint and timestamped records - Added `favorites:index` and `favorites:toggle` views with AJAX support for toggling favorites - Built templates and front-end assets for the favorites page and integration with item grids - Extended header with favorites link and dynamic counter - Added tests covering models, views, and templates for the favorites functionality - Updated admin to enable management of favorites via Django admin interface
33 lines
960 B
Python
33 lines
960 B
Python
from django.conf import settings
|
|
from django.db import models
|
|
|
|
from items.models import Item
|
|
|
|
|
|
class Favorite(models.Model):
|
|
user = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL,
|
|
on_delete=models.CASCADE,
|
|
related_name="favorite_entries",
|
|
verbose_name="Пользователь",
|
|
)
|
|
item = models.ForeignKey(
|
|
Item,
|
|
on_delete=models.CASCADE,
|
|
related_name="favorite_entries",
|
|
verbose_name="Товар",
|
|
)
|
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name="Дата добавления")
|
|
|
|
class Meta:
|
|
ordering = ("-created_at", "-id")
|
|
constraints = [
|
|
models.UniqueConstraint(fields=("user", "item"), name="unique_favorite_user_item"),
|
|
]
|
|
verbose_name = "Избранный товар"
|
|
verbose_name_plural = "Избранные товары"
|
|
|
|
def __str__(self):
|
|
return f"{self.user} -> {self.item}"
|
|
|