mirror of
https://github.com/Mistake35/Cedar-Django.git
synced 2026-07-18 00:21:14 +10:00
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.
This commit is contained in:
@@ -85,19 +85,7 @@ class ConversationAdmin(admin.ModelAdmin):
|
|||||||
search_fields = ('id', )
|
search_fields = ('id', )
|
||||||
raw_id_fields = ('source', 'target', )
|
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):
|
class PostAdmin(admin.ModelAdmin):
|
||||||
inlines = [CommentsInline]
|
|
||||||
raw_id_fields = ('creator', 'poll', )
|
raw_id_fields = ('creator', 'poll', )
|
||||||
search_fields = ('id', 'body', 'creator__username', )
|
search_fields = ('id', 'body', 'creator__username', )
|
||||||
list_display = ('id', 'creator', 'body', 'is_rm', )
|
list_display = ('id', 'creator', 'body', 'is_rm', )
|
||||||
|
|||||||
@@ -681,12 +681,11 @@ class Community(models.Model):
|
|||||||
objects = PostManager()
|
objects = PostManager()
|
||||||
real = models.Manager()
|
real = models.Manager()
|
||||||
def popularity(self):
|
def popularity(self):
|
||||||
if self.creator:
|
# Get the date 7 days ago from today
|
||||||
# don't count posts from the community owner.
|
start_date = timezone.now() - timedelta(days=7)
|
||||||
popularity = Post.objects.filter(community=self).exclude(creator=self.creator).count()
|
popularity = Post.objects.filter(community=self, created__gte=start_date)
|
||||||
else:
|
return popularity.count()
|
||||||
popularity = Post.objects.filter(community=self).count()
|
|
||||||
return popularity
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
def icon(self):
|
def icon(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user