# Django forms - prepopulate a Boolean field....

**URL:** <https://forum.djangoproject.com/t/django-forms-prepopulate-a-boolean-field/21688>\
**Category:** Forms & APIs\
**Created:** [June 17, 2023, 9:44pm UTC](https://forum.djangoproject.com/t/django-forms-prepopulate-a-boolean-field/21688 "2023-06-17T21:44:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![doc1977](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/doc1977/32/13416_2.png) [@doc1977](https://forum.djangoproject.com/u/doc1977)\
**Post date:** [June 17, 2023, 9:44pm UTC](https://forum.djangoproject.com/t/django-forms-prepopulate-a-boolean-field/21688/1 "2023-06-17T21:44:28Z")

</div>

Hi again out there,

I am dealing with “Create/Update” part of CRUD in my Django project at the moment and was encountering several Problems I could solve by using google and literature 😉

But one thing is left that gets me crazy: BooleanFields!

I have several forms in my project to populate the Database…and I am using some of the forms also for altering and updating data. So therefore I prefill the forms in case of update/altering with the corresponding dataset of my database.

My problem? If you have in forms.py a ModelForm corresponding to your EmploymentsModel:

```auto
...
  keep_data = forms.BooleanField(label='Daten löschen?', required=False,
                                 widget=forms.RadioSelect(choices=KEEP_DATA_CHOICES, attrs={
                                     'class': 'border border-black border-1 rounded-2 bg-secondary-subtle m-1',
                                     'required': 'True',
                                 }))
...

```

and then I try to call the Form again in your views.py with:

```auto
(some request if/then things here)
id_alter = request.POST['alterEmployment']
formdata = Employments.objects.get(id=id_alter)
form = EmploymentsForm(instance=formdata)
(some other stuff there, ending in handing over "form" as context)

```

and sent this from as context to template, I get properly prefilled all form fields except the BooleanForm of “keep\_data”…

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 17, 2023, 11:12pm UTC](https://forum.djangoproject.com/t/django-forms-prepopulate-a-boolean-field/21688/2 "2023-06-17T23:12:41Z")

</div>

What is your `KEEP_DATA_CHOICES`?

---

<div class="post-metadata">

**Author:** ![doc1977](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/doc1977/32/13416_2.png) [@doc1977](https://forum.djangoproject.com/u/doc1977)\
**Post date:** [June 18, 2023, 6:31am UTC](https://forum.djangoproject.com/t/django-forms-prepopulate-a-boolean-field/21688/3 "2023-06-18T06:31:00Z")

</div>

Sorry, i forgot to include this:

```auto
    KEEP_DATA_CHOICES = (
        ["1", "Yes"],
        ["2", "No"],
    )

```

---

<div class="post-metadata">

**Author:** ![Rigo-Villalta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rigo-villalta/32/5667_2.png) [@Rigo-Villalta](https://forum.djangoproject.com/u/Rigo-Villalta)\
**Post date:** [June 18, 2023, 8:17pm UTC](https://forum.djangoproject.com/t/django-forms-prepopulate-a-boolean-field/21688/4 "2023-06-18T20:17:55Z")

</div>

I think you should use:

```auto
KEEP_DATA_CHOICES = (
       (True, "Yes"),
       (False, "No")
    )

```

---

<div class="post-metadata">

**Author:** ![doc1977](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/doc1977/32/13416_2.png) [@doc1977](https://forum.djangoproject.com/u/doc1977)\
**Post date:** [June 19, 2023, 4:06pm UTC](https://forum.djangoproject.com/t/django-forms-prepopulate-a-boolean-field/21688/5 "2023-06-19T16:06:03Z")

</div>

Well…how can I say… OF COURSE I SHOULD 🙈 🙈 🙈

Thx 👍
