from __future__ import annotations from django.db import models from posthog.models.scoping.root_mixin import TeamScopedRootMixin from posthog.models.utils import CreatedMetaFields, UpdatedMetaFields, UUIDModel from posthog.utils import generate_short_id class Shoutout(TeamScopedRootMixin, UUIDModel, CreatedMetaFields, UpdatedMetaFields): class Status(models.TextChoices): PENDING = "pending", "Pending" SENDING = "sending", "Sending" SENT = "sent", "Sent" PARTIALLY_FAILED = "partially_failed", "Partially failed" FAILED = "failed", "Failed" all_teams = models.Manager() # noqa: DJ012 team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, db_constraint=False, related_name="+") created_by = models.ForeignKey( "posthog.User", on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False, related_name="+" ) short_id = models.CharField(max_length=12, blank=True, default=generate_short_id) message = models.TextField() status = models.CharField(max_length=20, choices=Status.choices, default=Status.PENDING) total_channels = models.PositiveIntegerField(default=0) sent_count = models.PositiveIntegerField(default=0) failed_count = models.PositiveIntegerField(default=0) sent_at = models.DateTimeField(null=True, blank=True) class Meta(TeamScopedRootMixin.Meta): # The table and index keep their pre-rename names, so the rename needs no DDL. db_table = "customer_analytics_announcement" default_manager_name = "all_teams" indexes = [ models.Index(fields=["team_id", "-created_at"], name="ca_announcement_team_idx"), ] def __str__(self) -> str: return f"Shoutout({self.short_id}, status={self.status})"