Необходимо вывести разницу между датой создания темы 'topic' и текущей датой. Разница в колличестве дней. Выводится, но только хардкордное число. Как вывести динамически?
Прилагаю модель forum.models.py
class Topic(models.Model):
name = models.CharField(max_length=200)
category = models.ForeignKey(
Category, verbose_name="Category", on_delete=models.SET_NULL, null=True, related_name='topic'
)
content = models.TextField()
likes = models.ManyToManyField(User, related_name='topic_likes', default=None, blank=True)
created = models.DateTimeField(auto_now_add=True)
tags = TaggableManager()
slug = models.SlugField(max_length=130, unique=True, default=uuid.uuid1)
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='topic_bookmark')
# e = localdate()
e = datetime.date.today()
objects = models.Manager()
def __str__(self):
return self.name
<b>def d_date(self):
return self.e - self.created.strptime('2022-8-26', '%Y-%m-%d').date()</b>
def total_likes(self):
return self.likes.count()
def get_absolute_url(self):
# return reverse("forum:topic_detail", kwargs={"slug": self.url})
return reverse_lazy('forum:topic_detail', kwargs={'slug': self.slug})
def tag_list(self) -> str:
return u", ".join(o.name for o in self.tags.all())
class Meta:
verbose_name = 'Topic'
verbose_name_plural = 'Topics'
и html
{{topic.d_date}}