In Django, I have the following models:
class Pink(models.Model):
...
class White(models.Model):
...
pinks = models.ManyToManyField(Pink)
...
At some point, I needed to define an ordering of Pinks
inside a White
(in order to have White1.pinks: P1, P2, P3
instead of a random White1.pinks: P2, P3, P1
),
so I've created
class PinkInWhite(models.Model):
pink = models.ForeignKey(Pink)
white = models.ForeignKey(White)
position = models.PositiveIntegerField("pink's position inside this white")
class Meta:
ordering = ['white','position']
Question 1: is this the better solution?
Question 2: This is obviously redundant: I still have a pinks
field in my White
model, because I need it in other situations which didn't require an ordering. Can I keep it, or is it better to remove it, and always use the PinkInWhite
relation model instead?
(Model names are fictional. For simplify the question I didn't use model's real names, and talking about Mr. X and Mr. Y wouldn't help readability...)