Skip to content

Commit 721b3ee

Browse files
committed
Fix Link unique_together constraint
1 parent 4aef9f1 commit 721b3ee

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.3 on 2023-07-20 12:03
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("contenttypes", "0002_remove_content_type_name"),
10+
("core", "0003_link"),
11+
]
12+
13+
operations = [
14+
migrations.AlterUniqueTogether(
15+
name="link",
16+
unique_together={("link", "content_type", "object_id")},
17+
),
18+
]

core/models.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ class Link(Model):
2424
content_object = GenericForeignKey("content_type", "object_id")
2525

2626
class Meta:
27-
unique_together = ("content_type", "object_id")
27+
unique_together = (
28+
"link",
29+
"content_type",
30+
"object_id",
31+
)
2832
verbose_name = "Ссылка"
2933
verbose_name_plural = "Ссылки"
3034

@@ -51,7 +55,11 @@ class Like(Model):
5155
content_object = GenericForeignKey("content_type", "object_id")
5256

5357
class Meta:
54-
unique_together = ("user", "content_type", "object_id")
58+
unique_together = (
59+
"user",
60+
"content_type",
61+
"object_id",
62+
)
5563
verbose_name = "Лайк"
5664
verbose_name_plural = "Лайки"
5765

@@ -81,7 +89,11 @@ class View(Model):
8189
content_object = GenericForeignKey("content_type", "object_id")
8290

8391
class Meta:
84-
unique_together = ("user", "content_type", "object_id")
92+
unique_together = (
93+
"user",
94+
"content_type",
95+
"object_id",
96+
)
8597
verbose_name = "Просмотр"
8698
verbose_name_plural = "Просмотры"
8799

0 commit comments

Comments
 (0)