Faq/Blog categories admin improvements
authorKostas Papadimitriou <kpap@grnet.gr>
Tue, 31 Jul 2012 11:12:05 +0000 (14:12 +0300)
committerKostas Papadimitriou <kpap@grnet.gr>
Tue, 31 Jul 2012 11:12:05 +0000 (14:12 +0300)
display related objects count instead of object list

cloudcmsblog/admin.py
cloudcmsblog/models.py
cloudcmsfaq/admin.py
cloudcmsfaq/models.py

index 585c6e3..8e828d7 100644 (file)
@@ -72,7 +72,8 @@ class EntryAdmin(item_editor.ItemEditor):
 
 class CategoryAdmin(admin.ModelAdmin):
     inlines = [CategoryTranslationInline]
-    list_display = ['__unicode__', 'entries']
+    list_display = ['__unicode__', 'entries_count', 'ordering']
+    list_editable = ['ordering']
     search_fields = ['translations__title']
 
     def entries(self, obj):
index 7fabba9..989f19f 100644 (file)
@@ -73,6 +73,9 @@ class Category(models.Model, translations.TranslatedObjectMixin):
 
     objects = translations.TranslatedObjectManager()
 
+    def entries_count(self):
+        return self.blogentries.count()
+
     def __unicode__(self):
         trans = translations.TranslatedObjectMixin.__unicode__(self)
         return trans or _('Unnamed category')
index 1cf8a77..d9b5fc4 100644 (file)
@@ -69,7 +69,7 @@ class QuestionAdmin(item_editor.ItemEditor):
 
 class CategoryAdmin(admin.ModelAdmin):
     inlines = [CategoryTranslationInline]
-    list_display = ['__unicode__', 'faqs', 'ordering']
+    list_display = ['__unicode__', 'faqs_count', 'ordering']
     list_editable = ['ordering']
     search_fields = ['translations__title']
 
index 33b149a..2101105 100644 (file)
@@ -69,14 +69,17 @@ class Category(models.Model, translations.TranslatedObjectMixin):
     image = MediaFileForeignKey(MediaFile, blank=True, null=True)
     class_name = models.CharField(_('class_name'), max_length=200, blank=True, null=True)
 
+    def faqs_count(self):
+        return self.faqs.count()
+
     class Meta:
         verbose_name = _('category')
         verbose_name_plural = _('categories')
         ordering = ['ordering',]
 
     objects = translations.TranslatedObjectManager()
-        
+
+
     def __unicode__(self):
         trans = translations.TranslatedObjectMixin.__unicode__(self)
         return trans or _('Unnamed category')
@@ -163,7 +166,7 @@ class Question(Base):
 
     def get_previous(self):
         return self.get_previous_by_published_on(category=self.category, service=self.service)
-    
+
     def get_absolute_url(self):
         try:
             r = reverse('cloudcmsfaq_question_detail', 'cloudcmsfaq.urls', (),