﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12406	Model Meta ordering bug with manytomany field	pbzrpa	nobody	"There seems to be a problem with ordering in a model meta class when you have a manytomany field in the model. It sorts the queryset grouped by the manytomany field.

Example:

{{{
class RelationType(models.Model):
    name = models.CharField(max_length = 30)
    editable = models.BooleanField(default=True)

    def __unicode__(self):
        return u'%s' % self.name

class Relation(models.Model):
    code = models.CharField(max_length = 20, primary_key = True)
    relationtype = models.ManyToManyField(RelationType)
    short_name = models.CharField(max_length = 30)
    full_name = models.CharField(max_length = 100, null = True, blank = True)
    pref_comm = models.ForeignKey(RelationCommunicationType, verbose_name = 'Perferred Comm')

    def __unicode__(self):
        return u'%s' % self.short_name

    class Meta:
        ordering = ('short_name',)
}}}

When you do Relation.objects.all() it sorts according to the short name but in lists grouped by the manytomany field.

So you would have a result like:

{{{
Short Name   |   Type
ab           |   Sup
abc          |   Sup
bcd          |   Sup
abcd         |   Cust
}}}

instead of 

{{{
Short Name   |   Type
ab           |   Sup
abc          |   Sup
abcd         |   Cust
bcd          |   Sup
}}}


"		closed	Uncategorized	1.1		worksforme			Unreviewed	0	0	0	0	0	0
