class Message(models.Model):
FEEDBACK = 'feedback'
NEW_FEATURE_IDEA = 'feature'
BUG = 'bug'
OTHER = 'other'
MESSAGE_TYPE = (
(FEEDBACK, 'Feedback'),
(NEW_FEATURE_IDEA, 'New feature idea'),
(BUG, 'Bug'),
(OTHER, 'Other'),
)
user = models.ForeignKey(User, default='1', null=True, blank=True, on_delete=models.SET_NULL)
title = models.CharField(blank=True, max_length=250)
message = models.TextField()
published_at = models.DateTimeField(auto_now_add=True, auto_now=False, null=True) # Время добавления
updated = models.DateTimeField(auto_now_add=False, auto_now=True, null=True) # Время обновления
message_type = models.CharField(choices=MESSAGE_TYPE, default=FEEDBACK, max_length=250)
slug = models.SlugField(unique=True)
class Meta:
ordering = ('-published_at', '-updated')
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('message:detail')
def get_api_url(self):
return reverse("message:detail", kwargs={"slug": self.slug})