2012-12-17 35 views

回答

1

我認爲,這需要模型的變化,因爲當產品被添加到購物車時,名稱和選項被保存到說明中:

class Cart(models.Model): 
    ... 
    item.description = unicode(variation) 

class ProductVariation(Priced): 
    ... 
    def __unicode__(self): 
     """ 
     Display the option names and values for the variation. 
     """ 
     options = [] 
     for field in self.option_fields(): 
      if getattr(self, field.name) is not None: 
       options.append("%s: %s" % (unicode(field.verbose_name), 
              getattr(self, field.name))) 
     return ("%s %s" % (unicode(self.product), ", ".join(options))).strip() 

UPD:

您可以添加字段SelectedProduct類:

options = CharField(_("Options"), max_length=200) 

Add方法ProductVariation類:

def options_text(self): 
    options = [] 
    for field in self.option_fields(): 
     if getattr(self, field.name) is not None: 
      options.append("%s: %s" % (unicode(field.verbose_name), 
             getattr(self, field.name))) 
    return ", ".join(options).strip() 

def __unicode__(self): 
    """ 
    Display the option names and values for the variation. 
    """   
    return ("%s %s" % (unicode(self.product), self.options_text())).strip() 
在車類

更改方法方法add_item:

item.description = unicode(variation.product) 
item.options = variation.options_text() 
+0

可否請您更改模型文件代碼,並將其發送給我...我 –

+0

更新了答案。 – sneawo

相關問題