Files
links/.history/backend/api/models_20250507140013.py

45 lines
1.6 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.db import models
from django.conf import settings
class LinkGroup(models.Model):
owner = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='api_link_groups' # уникальное имя, чтобы не конфликтовать с links app
)
name = models.CharField(max_length=100)
order = models.PositiveIntegerField(default=0)
description = models.TextField(blank=True, null=True)
icon = models.ImageField(
upload_to='link_groups/',
null=True,
blank=True,
help_text='Иконка группы ссылок'
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
is_public = models.BooleanField(default=False, help_text='Публичная группа ссылок')
is_favorite = models.BooleanField(default=False, help_text='Избранная группа ссылок')
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'
)
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