0

I have a basket object, each basket could have many balls and a ball could be on many baskets, moreover each ball has many colors but one color is for one ball only. Models example:

class Basket(models.Model):
    name = models.CharField(max_length = 100)

class Ball(models.Model):
    basket = models.ManyToManyField(Basket,  )

class Color(models.Model):
    ball = models.ForeignKey(Ball, on_delete = models.CASCADE)

Each object has many other fields, not relevant

I want in admin site when create a basket, select which ball and which color per ball. I tried inline, but it adds a new ball, i want just select existing ball and related color.

PS:IMHO This is not a duplicate of this question because select Basket is covered but not select Color per ball.

Thanks all

Update

My app is an excercise, i want to create a basket with undefined number of balls and choose which color has any of the ball from a list of color assigned to that ball.
You could call also basket as object1, ball as object2 and color as object3, it doesn't matter.
All should be using admin site.
That's my goal.

backit
  • 42
  • 8
  • And a ball can have many colours? It's not clear what you mean by "select related color" since your models would rather have you select one ball for each color. – dirkgroten Dec 10 '19 at 14:16
  • Note that if you add `ball_set` as field on your admin model for `Basket` (the reverse relationship to `Ball` -> `Basket`), you'll get a multiple select widget where you can just select the balls (similar to selecting permissions in groups). – dirkgroten Dec 10 '19 at 14:18
  • @dirkgroten thanks to be so fast, yes in admin you create a color and select a ball, but you can create many colors with the same ball, so one ball has many colors – backit Dec 10 '19 at 14:31
  • @dirkgroten and what about color? with ball_set i choose ball. Related means that i created a color red for ball 1, color green for ball 1 and when i create the basket i want to choose which ball with which color (not with all colors but only color related to the specific ball), many thanks – backit Dec 10 '19 at 14:36
  • But a basket only has a relationship to a ball, not to a color. So you can’t choose a color to put in the basket since if you put a ball and the ball has 4 colors, you “put” all 4 colors in the basket. That’s why I’m a bit confused by your models. – dirkgroten Dec 10 '19 at 14:41
  • But if i put a relationship between basket and color, i can choose every existing color, not only those from choosen ball, so .... ? – backit Dec 11 '19 at 09:45
  • Maybe you should take a step back and explain to us the general picture. What are you trying to achieve? What's your app about? – dirkgroten Dec 11 '19 at 10:51
  • I updated my question, hope it's clearer now – backit Dec 12 '19 at 08:52

0 Answers0