Answer the question
In order to leave comments, you need to log in
How to create a form for foreign keys of a model?
Here is what I am trying to do. I'm wondering if anyone can suggest a good approach:
models.py:
class Color(models.Model):
name = models.CharField(...
class Speed(models.Model):
name = models.CharField(...
class Dog(models.Model):
name = models.CharField(...
speed = models.ForeignKey(Speed...
class DogRequest(models.Model):
id_name = models.PositiveSmallIntegerField()
color = models.ForeignKey(Color...
dog = models.ForeignKey(Dog...
request_time = models.DateTimeField()
class DogRequestForm(ModelForm):
class Meta:
model = DogRequest
fields = ('id_name','request_time','color','speed')
color = forms.ModelChoiceField(queryset=Color.objects.all())
speed = forms.ModelChoiceField(queryset=Speed.objects.all())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question