import uuid from django.db import models from django.urls import reverse from django.utils import timezone class Post(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) owner = models.ForeignKey( "lyric.User", related_name="posts", blank=True, null=True, on_delete=models.CASCADE, ) shared_with = models.ManyToManyField( "lyric.User", related_name="shared_posts", blank=True, ) @property def name(self): return self.lines.first().text def get_absolute_url(self): return reverse("billboard:view_post", args=[self.id]) class Line(models.Model): text = models.TextField(default="") post = models.ForeignKey(Post, default=None, on_delete=models.CASCADE, related_name="lines") class Meta: ordering = ("id",) unique_together = ("post", "text") def __str__(self): return self.text class Brief(models.Model): """A slide-down notification record. Owner = whose attention; post = where FYI navigates (and where mark-read happens on GET); line = the specific appended Line that triggered it (so the banner can surface its text). `kind` discriminates the affordances the banner renders. NOTE_UNLOCK Briefs get a clickable square that jumps direct to my_notes.html; SHARE_INVITE Briefs render the invitation copy; USER_POST is the legacy user-authored compose flow. Magic-link confirmation + invalid-link banners use the same Gaussian-glass visual styling but ride no Brief row (transient one-shot). """ KIND_NOTE_UNLOCK = "note_unlock" KIND_USER_POST = "user_post" KIND_SHARE_INVITE = "share_invite" KIND_CHOICES = [ (KIND_NOTE_UNLOCK, "Note unlock"), (KIND_USER_POST, "User post"), (KIND_SHARE_INVITE, "Share invite"), ] id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) owner = models.ForeignKey( "lyric.User", related_name="briefs", on_delete=models.CASCADE, ) post = models.ForeignKey( Post, related_name="briefs", on_delete=models.CASCADE, ) # Line is nullable because a share_invite-style Brief can race ahead of its # async-appended Line write; the post FK alone is enough to navigate. line = models.ForeignKey( Line, related_name="briefs", on_delete=models.CASCADE, null=True, blank=True, ) is_unread = models.BooleanField(default=True) kind = models.CharField( max_length=32, choices=KIND_CHOICES, default=KIND_USER_POST, ) title = models.CharField(max_length=255, blank=True) created_at = models.DateTimeField(default=timezone.now) class Meta: ordering = ["-created_at"] def __str__(self): return ( f"Brief({self.kind}, {self.owner.email}, " f"unread={self.is_unread})" )