blog/tblog/models.py
2024-12-31 19:56:46 -05:00

31 lines
964 B
Python

from typing import TYPE_CHECKING
from django.contrib import admin as django_admin
from django.contrib.admin.exceptions import AlreadyRegistered # type: ignore
from django.db import models
class tBUser(models.Model):
username = models.CharField(max_length=30, unique=True, primary_key=True)
if TYPE_CHECKING:
posts = models.Manager["tBPost"]
def __str__(self) -> str:
return self.username
class tBPost(models.Model):
u_by = models.ForeignKey(tBUser, on_delete=models.CASCADE, related_name="posts")
url = models.CharField(max_length=250)
title = models.TextField(max_length=1_000)
content = models.TextField(max_length=500_000)
timestamp = models.IntegerField()
text_format = models.CharField(max_length=10) # plain, mono, markdown, html ... (more to come?)
class Meta:
unique_together = ("u_by", "url")
try:
django_admin.site.register((tBUser, tBPost))
except AlreadyRegistered:
...