M
M
maniacus262020-11-30 11:56:47
Django
maniacus26, 2020-11-30 11:56:47

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


In the form, one of the fields is a drop-down list (foreign key)
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


How to exclude several entries in the drop-down list (ForeignKey to the doc_vid table), for example, the first and second, leaving the third and fourth?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question