Есть список публикаций 'topic' . Не могу понять, как вывести число пользователей, которые смотрели ту или иную публикацию (topic). Причём не колличество посещений (колличество просмотров я уже вывел), а именно колличество пользователей.
Мой кол:
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')
views = models.ManyToManyField(Ip, related_name="post_views", blank=True)
objects = models.Manager()
def total_views(self):
return self.views.count()
def __str__(self):
return self.name
def d_date(self):
z = self.created.strptime(str(self.created), '%Y-%m-%d %H:%M:%S.%f+%U:%W')
r = datetime.datetime.today()
e = r - z
return e
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'
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=255, unique=True)
first_name = models.CharField(max_length=30, null=True, blank=True)
last_name = models.CharField(max_length=30, null=True, blank=True)
email = models.EmailField(max_length=255, unique=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(u'date joined', default=timezone.now)
objects = UserManager()
avatar = models.ImageField(settings.AUTH_USER_MODEL, default='media/no_image.jpg', blank=True)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email', 'password', 'avatar']