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

37 lines
1022 B
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='groups'
)
title = models.CharField(max_length=100)
order = models.PositiveIntegerField(default=0)
class Meta:
ordering = ['order']
unique_together = ('owner', 'title')
def __str__(self):
return f"{self.owner.username} {self.title}"
class Link(models.Model):
group = models.ForeignKey(
LinkGroup,
on_delete=models.CASCADE,
related_name='links'
)
title = models.CharField(max_length=200)
url = models.URLField()
order = models.PositiveIntegerField(default=0)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ['order']
def __str__(self):
return self.title