Files
links/.history/backend/api/models_20250506131224.py
2025-05-06 20:44:33 +09:00

35 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.conf import settings
from django.db import models
class LinkGroup(models.Model):
owner = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='api_link_groups' # теперь уникально
)
name = models.CharField(max_length=100)
order = models.PositiveIntegerField(default=0)
def __str__(self):
return f"{self.owner.username} - {self.name}"
class Link(models.Model):
owner = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='links' # оставляем 'links' — у User нет такого поля
)
group = models.ForeignKey(
LinkGroup,
on_delete=models.SET_NULL,
null=True, blank=True,
related_name='links'
)
title = models.CharField(max_length=200)
url = models.URLField()
icon = models.URLField(blank=True, null=True)
order = models.PositiveIntegerField(default=0)
def __str__(self):
return self.title