views:

240

answers:

1

Hi, I have a simple model like this one:

class Artist(models.Model):
   surname = models.CharField(max_length=200)
   name = models.CharField(max_length=200, blank=True)
   slug = models.SlugField(unique=True)
   photo = models.ImageField(upload_to='artists', blank=True)
   bio = models.TextField(blank=True)  

class Images(models.Model):
   title = models.CharField(max_length=200)
   artist = models.ManyToManyField(Artist)
   img = models.ImageField(upload_to='images')

Well, I started to insert some Artists and then I went to the Images insert form. I found that the many-to-many artist box is unsorted:

  • Mondino Aldo
  • Aliprandi Bernardo
  • Rotella Mimmo
  • Corpora Antonio

Instead of:

  • Aliprandi Bernardo
  • Corpora Antonio
  • Mondino Aldo
  • Rotella Mimmo

How can I solve this issue? Any suggestion? Thank you in advance.

Matteo

+3  A: 

Set ordering on the Article's inner Meta class.

class Article(models.Model):
    ....

    class Meta:
        ordering = ['surname', 'name']
Daniel Roseman
Great, thank you Daniel. As you can see I'm quite a noob! :)
Matteo