V
V
Villian_Os2020-09-30 11:22:36
Django
Villian_Os, 2020-09-30 11:22:36

How to convert select to checkbox in django form?

Please help me understand how to remake the form in my application. There is a field in the form with the choice of organization. Here is its field from the model -

class Report(models.Model):
    organisation = models.ForeignKey(Organisation, default=None, null=True, on_delete=models.DO_NOTHING)

Created a form
class ReportForm(forms.ModelForm):
    class Meta:
        model = Report
        fields = (
            'name',
            'organisation',
            'columns',
            'message'
        )

Passed the form to the template.

The entry is sent to the organization that was selected accordingly. Question - And how to make it so that you can select by ticking the checkboxes, so that a record is also transmitted for the selected ones? That is, not alone, but chosen. I apologize if the question is stupid, I read the documentation, but without examples I did not understand how it could work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-09-30
@bacon

Well, your model implies only one organization, but ForeignKey himself did it, if you need a lot, then ManyToManyField.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question