Consider something like a tag hierarchy model: class Tag(models.Model): name = models.CharField(maxlength = 50, unique = True) parent = models.ForiegnKey('self', related_name='child', null = True, blank = True) class Meta: ordering = ['parent', 'name'] def __str__(self): if self.parent_id is not None: prefix = str(self.parent) + '/' else: prefix = '' return prefix + self.name
Now, this model almost, but not quite, orders the tags in a "natural" fashion. That is, if I have a tag structure that looks like this: Life Universe Everything Software Python Django Design Theory I will get an ordering of: Life Software Life/Everything Life/Universe Software/Design Software/Python Software/Design/Theory Software/Python/Django (actually, for some reason that I don't yet understand and suspect is a bug, I don't get the ordering in the admin list view, but it does get ordered that way in select boxes and stuff that I care about. Let's ignore that for now.) What I really want is for the ordering to have sub-categories under the parent category. This would be easy if I could sort on the str() value for each object, since the natural ordering is the lexicographic ordering of the strings. Is there an easy way to do this? I seem to have come across it a few times now (I like hierarchies, so sue me). Unfortunately, Meta.ordering seems to want a real field, not a method (which Admin.list_display can take) or a property. So am I missing something, or is this even a common need for other people? Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---