How to get one form from a model and another model associated with it?
# models.py
from django.db import models
class BioInformation (models.Model):
eyes_color = models.CharField (max_length = 15)
weight = models.IntegerField ()
height = models.IntegerField ()
class Person (models.Model):
first_name = models.CharField (max_length = 30)
second_name = models.CharField (max_length = 60)
bio_info = models.OneToOneField (BioInformation, on_delete = models.CASCADE)
# forms.py
from .models import Person
class PersonForm (ModelForm):
class Meta:
model = Person
fields = '__all__'
labels = {
'first_name': 'name',
'second_name': 'last name',
'eyes_color': 'eye color',
'weight': 'weight',
'height': 'height'
}
# views.py
from django.views.generic import FormView
from .forms import PersonForm
class PersonFormView (FormView):
form_class = PersonForm
template_name = 'board / auth_user_page.html'
success_url = '/'
For example, in the example above it turns out:
And I want that, in addition to the elements for from the Person model, elements for input from the BioInformation model are BioInformation , and not an incomprehensible drop-down list