[Answer]-Forcing the order of many-to-many-field

1👍

You should be able to define the sort order using a through class, which takes care of the original problem (untested, handle with care):

class ScoreBoard(models.Model):
    pass

class Match(models.Model):
    boards = models.ManyToManyField(ScoreBoard, through="MatchBoard")

class MatchBoard(models.Model):
    match = models.ForeignKey(Match)
    board = models.ForeignKey(ScoreBoard)
    sortorder = models.PositiveIntegerField()

    class Meta:
        ordering = ('sortorder', )
👤cvk

Leave a comment