Let's say I have an app that's supposed to allow (fashion designers) to post a "Design with Customizations"
The wanted result in the template is like this :
Dress: Please select material : 1- wool, 2-cotton, 3-cashmere (only one can be selected)
What colours would you like : black $10, blue, red, yellow (multiple selections)
I'd like to allow designers to add options with choices and decide if (customers) can select one choice (radio button group) or multiple choices (checkboxes) with extra charge and decide default ones...
** Models.py **
class Choice(models.Model):
# e.g red
name = models.CharField(max_length=500)
extra_charge = models.DecimalField(default=0, max_digits=10, decimal_places=2)
class Option(models.Model):
# what colours?
name = models.CharField(max_length=500)
choice = models.ForeignKey(Choice)
class Dress(models.Model):
options = models.ManyToManyField(Choice, related_name='Dress')
name = models.CharField(max_length=500)
price = models.DecimalField(max_digits=10, decimal_places=2)
I have been working on Django for a while now but I have no idea how to go about this....
According to my idea, Your Dress Model should not have an option field, also, you should create a foreign key called dress # related to Dress Model in your Option Model.
Each time when you need designers to add an option with choices, just show him the form page created from Option Model, I think this is your solution!