model.py
class Category(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
def __unicode__(self):
return self.name
class Item(models.Model):
listing = models.CharField(max_length=1, choices=LISTING_TYPES, default='T')
name = models.CharField(max_length=255)
category = models.ForeignKey(Category)
department = models.CharField(max_length=255)
description = models.TextField()
posted_on = models.DateTimeField(auto_now_add=True)
forms.py
class ItemForm(forms.Form):
listing = forms.ChoiceField(choices=LISTING_TYPES, initial='T')
name = forms.CharField(max_length=255)
category = forms.ModelChoiceField(Category.objects.all())
department = forms.CharField(max_length=255)
description = forms.CharField(widget=forms.Textarea)
当我转到表单时,选择下拉菜单,它只显示“类别对象”。如何将名称存储在Category?
中