From 376afb43ce9476e7389e316c3d56699d89caab1c Mon Sep 17 00:00:00 2001 From: some weird guy <120821766+Mistake35@users.noreply.github.com> Date: Sat, 9 Sep 2023 19:55:38 -0700 Subject: [PATCH] hmm - Removed the comments inline thing because it was slow - Sorting by popularity is now limited by posts within 7 days. I am not sure how this will impact performance but hopefully it wont be as slow. --- closedverse_main/admin.py | 12 ------------ closedverse_main/models.py | 11 +++++------ 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/closedverse_main/admin.py b/closedverse_main/admin.py index cbf6fdc..ab8b38a 100644 --- a/closedverse_main/admin.py +++ b/closedverse_main/admin.py @@ -85,19 +85,7 @@ class ConversationAdmin(admin.ModelAdmin): search_fields = ('id', ) raw_id_fields = ('source', 'target', ) -class CommentsInline(admin.TabularInline): - model = models.Comment - extra = 0 - fields = ('creator', 'body', 'is_rm', ) - readonly_fields = ('creator', ) - def has_add_permission(self, request, obj=None): - return False - def has_delete_permission(self, request, obj=None): - return False - - class PostAdmin(admin.ModelAdmin): - inlines = [CommentsInline] raw_id_fields = ('creator', 'poll', ) search_fields = ('id', 'body', 'creator__username', ) list_display = ('id', 'creator', 'body', 'is_rm', ) diff --git a/closedverse_main/models.py b/closedverse_main/models.py index 981885a..14ca7ff 100644 --- a/closedverse_main/models.py +++ b/closedverse_main/models.py @@ -681,12 +681,11 @@ class Community(models.Model): objects = PostManager() real = models.Manager() def popularity(self): - if self.creator: - # don't count posts from the community owner. - popularity = Post.objects.filter(community=self).exclude(creator=self.creator).count() - else: - popularity = Post.objects.filter(community=self).count() - return popularity + # Get the date 7 days ago from today + start_date = timezone.now() - timedelta(days=7) + popularity = Post.objects.filter(community=self, created__gte=start_date) + return popularity.count() + def __str__(self): return self.name def icon(self):