Answer the question
In order to leave comments, you need to log in
How to get value from ModelForm?
I have a model
class Car(models.Model):
class ModelChoise(models.IntegerChoices):
Model_1 = 0
Model_2 = 1
Model_3 = 2
Model_4 = 3
name = models.TextField('Name')
model_id = models.IntegerField('model id', choices=ModelChoise.choices, default=1)
def __str__(self):
return self.name
class CarForm(ModelForm):
class Meta:
model = ExtraUser
fields = ['model_id']
{% for mykey,myvalue in form.model_id %}
{{ mykey }} : {{ myvalue }}
{% endfor %}
<!--
Model_1 : 0
Model_2 : 1
Model_3 : 2
Model_4 : 3
-->
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