Answer the question
In order to leave comments, you need to log in
How to exclude several records from a connection with an external table (ForeignKey)?
Good afternoon!
There is a simple model (Result) and a form that is associated with it.
class Result(models.Model):
id = models.AutoField(primary_key=True)
created_at = models.DateTimeField(auto_now_add=True)
doc_analis = models.BooleanField(blank=True, default=False)
doc_change_vid = models.ForeignKey(doc_vid, on_delete=models.SET_NULL, null=True, blank=True) # FK к таблице doc_vid
class ResultNew(CreateView):
model = result
fields = '__all__'
def get_form(self, form_class=None):
form = super().get_form(form_class)
form.helper = FormHelper()
form.helper.add_input(Submit('submit', 'Create', css_class='btn-primary'))
form.fields['doc_change'].label = "Изменение"
form.fields['doc_analis'].label = "Анализ"
form.fields['doc_change_vid'].label = "Вид документа" # FK выпадающий список (4 значения из таблицы doc_vid)
return form
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