Пример кода:
models.py
class BaseObject(models.Model): adress_object = models.CharField(max_length=100, blank=False, verbose_name='Адрес объекта', db_index=True, null=False) slug = models.SlugField(unique=True, blank=True, null=True, editable=False) class Dogovor(models.Model): object_d = models.ForeignKey(BaseObject, on_delete=models.PROTECT, verbose_name='Объект', db_index=True) num_contract = models.CharField(max_length=20, blank=False, verbose_name='Номер договора', db_index=True, null=False)
views.py
class DogovorCreateView(CreateView): model = Dogovor template_name = 'realestateworks/dogovor_create.html' form_class = DogovorForm success_url = '/realestateworks/'
dogovor_create.html
[code html+django]
{% extends "base_realestateworks.html" %}
{% block content %}
<div class="address">
<h1>Форма для нового договора по объекту</h1>
<form class="js-form-address" method="post">
{% csrf_token %}
{% for field in form %}
<div class="field">
{{ field.label }}
{{ field }}
</div>
{% endfor %}
<input type="submit" value="Создать">
</form>
</div>
{% endblock %}
[/code]