Answer the question
In order to leave comments, you need to log in
How to nest a form inside another form field?
Let's say we have an order and it has a buyer who refers to another table
class Order(model.Model)
user = models.ForeignKey(User, verbose_name='Клиент *')
buyer = models.ForeignKey(Buyer, verbose_name="Покупатель *", default=False)
...
class Buyer(model.Model)
user = models.ForeignKey(User, verbose_name='Клиент')
phone_number = models.CharField("Номер телефона *", blank=False, max_length=16)
...
class OrderForm(forms.ModelForm):
class Meta:
model = Order
fields = ['buyer', ...]
class BuyerForm(forms.ModelForm):
class Meta:
model = Buyer
fields = ['phone_number']
Answer the question
In order to leave comments, you need to log in
As in the Dzhang admin panel. Next to the selection field is a plus, by clicking which the desired form appears in a pop-up window.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question