From b73e3778d715b7c0b7421a400d6900b66a9fd3b3 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sat, 22 Sep 2018 01:28:39 -0400 Subject: [PATCH] Add seen count to totd admin --- totd/admin.py | 6 ++++-- totd/models.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/totd/admin.py b/totd/admin.py index 66eaf44..db99fff 100644 --- a/totd/admin.py +++ b/totd/admin.py @@ -22,11 +22,13 @@ class TipForm(forms.ModelForm): self.fields['view'].widget = forms.Select(choices=url_choices()) class TipAdmin(admin.ModelAdmin): - #raw_id_fields = ('seen_by',) list_filter =('level', 'view') - list_display = ('name', 'level', 'view', 'run_start', 'run_end') + list_display = ('name', 'level', 'view', 'run_start', 'run_end', 'seen_count') search_fields = ('name', 'view') form = TipForm + def seen_count(self, tip): + return tip.seen_by.count() + seen_count.short_description = 'Seen by' admin.site.register(Tip, TipAdmin) diff --git a/totd/models.py b/totd/models.py index 01ffab9..d766fb9 100644 --- a/totd/models.py +++ b/totd/models.py @@ -19,4 +19,7 @@ class Tip(models.Model): seen_by = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='seen_tips', blank=True) def tags(self): - return settings.MESSAGE_TAGS[self.level] \ No newline at end of file + return settings.MESSAGE_TAGS[self.level] + + def __str__(self): + return self.name \ No newline at end of file