Hello I have a Sujet that can have sub-Sujet recursively. Here is a test among several ones that does not work : class Sujet(models.Model): objects = None numero = models.PositiveSmallIntegerField() titre = models.CharField(max_length=100) partie = models.ForeignKey('self', models.CASCADE, blank=True, null=True, db_index=False)
def __str__(self): if self.partie is None: s = '' else: s = str(self.partie) s2 = '' if len(s) > 0: for i, c in enumerate(s): if c.isdigit(): s2 = s[:(i+2)] elif c == ' ': break s = s2 + str(self.numero) + '. ' s += str(self.titre) return s @admin.register(Sujet) @admin.display(ordering='__str__') class SujetAdmin(admin.ModelAdmin): fields = ('partie', 'numero', 'titre') list_display = ('__str__',) The asked ordering does work. Apparently, it sorts by decreasing order of the Sujet creation. Serge Alard -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ff80ea5a-b04c-4cef-a5c0-47281641e82bn%40googlegroups.com.