In Django, I've the next models:
class Pink(models.Model): ... class White(models.Model): ... pinks = models.ManyToManyField(Pink) ...
Sooner or later, I desired to define an ordering of
Pinks in the
(to be able to have
White1.pinks: P1, P2, P3 rather than a random
White1.pinks: P2, P3, P1),
so I have produced
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 the greater solution?
Question 2: This really is clearly redundant: I have a
pinks area during my
White model, because I want it in other situations which did not require an ordering. Can One ensure that it stays, or is it more beneficial to get rid of it, and try to make use of the
PinkInWhite relation model rather?
(Model names are imaginary. For simplify the question I did not use model's real names, and speaking about Mr. X and Mr. Y wouldn't help readability...)
It is dependent how well-defined your intended me is.
If you are just searching for some purchased pinks in whites, you can easily stuff my way through one table and steer clear of the junction table
But when you may later on wish to have other tints besides tints of red-colored, then getting pinks tied straight to whitened while you do is simply too limited. Just leave whites as whites, and make up a junction table connecting the pinks towards the approriate whites (with ordering). Then you've the versatility to create tints of blues, yellows, whatever.
However the short response to your question, that which you have is going to be functional.