Hi there,

At the moment, i'm building a inclusion tag for using on my blog
software to show all the categories, kind of like how Wordpress does
it.  The tag works fine and displays the data, sorted in order of the
name:

@register.inclusion_tag("blog/category_list.html")
def category_list(order="name"):
    cats = Category.objects.all().order_by(order)
    return {'categories': cats}

However what I'd like to do is also be able to order by the number of
entries associated with this category, so it's weight based rather
than alphabetical.

My Entry model has a ManyToManyField linked with categories, and my
Category model doesn't store this number, but for example it
calculates the value for the admin in a num_entries function:

class Category(models.Model):
    """ A Category is a way to manage the taxonomy of the site"""
    name=models.CharField(max_length=50) #The name of the category
    description=models.TextField()
    slug=models.CharField(max_length=75, null=True, blank=True)
    active=models.BooleanField()
    generate_feed=models.BooleanField()
    parent=models.ForeignKey('self', null=True, blank=True)
.....
    def num_entries(self):
        """Returns the number of entries in this category"""
        return self.entry_set.count()
    num_entries.short_description = "Number of Entries"

I'm wondering if there is any way possible to get this value in my
inclusion tag?  I had tried before to store this value in a field, but
couldn't get it to save, otherwise I would just pass in a field
'num_entries' so if anyone can suggest anything, that would be great.

Thanks,

-- 
Tane Piper
Blog - http://digitalspaghetti.me.uk
AJAX Pastebin - http://pastemonkey.org

This email is: [ ] blogable [ x ] ask first [ ] private

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to