具有用户定义属性的Django购物车

时间:2012-11-09 23:06:20

标签: django django-models django-forms

美好的一天。

我正在构建一个应用程序,用于在其中的部分订购打印和挣扎 除了从预定义值中选择之外,用户还可以输入自己的数据进行打印。

请考虑以下事项:

class PrintItem(models.Model):
    """ Something printable. Poster, t-shirt, mug, etc """
    name = models.CharField(max_length=20)

class AttributeType(models.Model):
    """ Size,colour, etc """
    name = models.CharField(max_length=20)

class Attribute(models.Model):
    """ Size: A4, A5 | Colour: Violet, Black """
    name = models.CharField(max_length=20)
    type = models.ForeignKey(AttributeType)

# And a join model
class PrintAttribute(models.Model):
    print_item = models.ForeignKey(PrintItem)
    attributes = models.ManyToManyField(Attribute)

# The user adds these to a cart
class Cart(models.Model):
    user = models.ForeignKey(User)

class CartItem(models.Model):
    cart = models.ForeignKey(Cart)
    print_item = models.ForeignKey(PrintItem)

这一切都很好。用户可以从预定义的属性中进行选择,但您建议我如何以及在何处实施用户输入功能? 用户找到要打印的项目,从预定义的属性(打印尺寸,墨水颜色)中进行选择,并可以输入自己的消息/标语以在项目上打印。

感谢任何建议。

1 个答案:

答案 0 :(得分:1)

如果仅在向购物车添加打印项目时输入用户自己的口号/消息,则口号/消息应为CartItem字段。