Commits

Guilherme Gondim committed d8cab1f

Queryset with only root nodes in AlbumList view

  • Participants
  • Parent commits 40e40e4

Comments (0)

Files changed (2)

File galeria/models.py

     def public(self):
         return super(AlbumManager, self).filter(is_public=True)
 
+    def public_root_nodes(self):
+        return super(AlbumManager, self).root_nodes().filter(is_public=True)
+
 
 class Album(MPTTModel):
     title = models.CharField(_('title'), max_length=256)
     def available_cover(self):
         if self.cover:
             return self.cover
-        elif self.parent:
-            return self.parent.available_cover
+        elif self.pictures.public():
+            return self.pictures.public().order_by('?')[0]
         else:
             return None
 

File galeria/views.py

 
 class AlbumList(generic.list.ListView):
     model = Album
-    queryset = Album.objects.public()
-    paginate_by = 20
+    queryset = Album.objects.public_root_nodes()
 
 
 class PictureDetail(generic.detail.DetailView):