我正在使用Django multiselectfield程序包,并且遇到了问题
ValueError: not enough values to unpack (expected 2, got 1)
我知道我在MultiSelectField
属性choices
中遇到问题,但是我不知道该怎么解决。
models.py
class Meal(models.Model):
restaurant = models.ForeignKey(Restaurant, on_delete=models.PROTECT)
category = models.ForeignKey(MealCategory, on_delete=models.PROTECT)
name = models.CharField(max_length=500)
short_description = models.CharField(max_length=500)
image = models.ImageField(upload_to='meal_images/', blank=False)
price = models.IntegerField(default=0)
#extras = models.OneToOneField('foodtaskerapp.Extra',related_name='is_extra' ,blank=True, null=True)
extras = MultiSelectField(choices ='foodtaskerapp.Extra().get_extras()')
def __str__(self):
return self.name
class Extra(models.Model):
extra_n = models.CharField(max_length=200)
meal = models.ForeignKey(Meal, on_delete = models.CASCADE, null=True, blank=True)
extra_price = models.IntegerField(default=0)
def __str__(self):
return self.extra_n
def get_extras(self):
return self.extra_n