I have the following model:
from django.db import model
class Fruit(models.Model):
fruit_name = models.CharField(max_length=100)
And A form like this:
from django import forms
from .models import SomeModel
class FruitForm(forms.ModelForm):
some_input = forms.CharField(max_length=100)
class Meta:
model = Fruit
fields = ['fruit_name']
This guide shows me how to create a dropdown like this:
fruit = [
('orange', 'Oranges'),
('cantaloupe', 'Cantaloupes'),
('mango', 'Mangoes'),
('honeydew', 'Honeydews'),
]
class TestForm(forms.Form):
some_input = forms.CharField(max_length=100)
favorite_fruit = forms.CharField(widget=forms.Select(choices=FRUIT_CHOICES))
What I want to happen is for the key/value tuple list to generate based on the fruit_id and fruit_name columns of the Fruit model, without the need to manually insert the data into the FruitForm.
What am I missing here?