I'm developing a simple webshop like application for a website. The shop is for various clothing equpment, wich can be ordered in different sizes. I've set up the following structure:
SHOP_SIZE_TYPES = (
('Letter', 'letter'),
('Number', 'number'),
)
class ShopSize(models.Model):
sizetype = models.CharField('Sizetype',max_length = 100, choices=SHOP_SIZE_TYPES)
size = models.CharField('Size', max_length = 100)
def __unicode__(self):
return self.size
class ShopEquipment(models.Model):
title = models.CharField("Navn", max_length = 100);
image = models.ImageField();
price = models.IntegerField("Pris")
image = models.ImageField(upload_to='shop_equipment');
availible_sizes = models.ManyToManyField(ShopSize);
def __unicode__(self):
return self.title
When a visitor buys a item, the following is to be stored in the database:
class OrderItem(models.Model):
order = models.ForeignKey('Order')
equipment = models.ForeignKey('ShopEquipment')
price = models.IntegerField('Price at time of purchase')
size = models.CharField('Size', max_length = 100);
My trouble is when I want to present a form for each Equipment, simply containing a send-button and a Select-meny containing the availible sizes for that specific item. I can't figure out how to populate that select-menu, based on which equipment that specific form i for!
Is there a way to do this, or should I actually just render the form manually in the templa开发者_如何学Pythonte, using html and {% for %} loops?
Thanks!
精彩评论