Answer the question
In order to leave comments, you need to log in
How to describe form fields if model data is linked via foreignkey?
Hi, some fields in the model are bound via foreignkey
//models.py
class Item(models.Model):
......
category = models.ForeignKey(Category, verbose_name=u'Укажите категорию')
......
class Category(models.Model):
name = models.CharField('Name', max_length=50)
slug = models.SlugField('Slug')
class EditForm(forms.ModelForm):
class Meta:
model = Item
fields = ('category', 'mode', 'type', 'delivery' )
Answer the question
In order to leave comments, you need to log in
class EditForm(forms.ModelForm):
category = forms.ModelChoiceField(
queryset=Category.objects.all(),
label='Categories',
widget=forms.Select()
)
class Meta:
model = Item
fields = ('category', 'mode', 'type', 'delivery' )
Category
from models. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question