I created a custom signup page.
I want the user to have, by default, two Boolean fields, is_nhs
and agree_conditions
.
However, the checked
attribute in my HTML is not working. The database does receive it. In fact, if I log in as superuser in the Django dashboard, the attribute is_nhs
and agree_conditions
are always set to false (red cross).
My custom user model:
class CustomUser(AbstractUser):
first_name = models.CharField(max_length=100, default='')
last_name = models.CharField(max_length=100, default='')
organization = models.CharField(max_length=100, default='')
location = models.CharField(max_length=100, default='')
postcode = models.CharField(max_length=100, default='')
phone = models.CharField(max_length=100, default='')
agree_conditions = models.BooleanField(default=True)
is_nhs = models.BooleanField(default=False)
def __str__(self):
return self.email
My signup.html
<form>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1" checked="checked">
<label class="form-check-label" for="exampleCheck1" name="agree_conditions">Agree conditions</label>
<a href="{% url 'conditions'%}">Click here to see the conditions you are accepting</a>
<div class="form-check" hidden>
<input class="form-check-input" type="radio" name="is_nhs" id="exampleRadios1" value="Yes" required checked>
<label class="form-check-label" for="exampleRadios1">
Yes
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
I tried to change unsuccessfully to checked_attribute
following this guide:
What's the proper value for a checked attribute of an HTML checkbox?
Moreover, I find it strange that agree_conditions
(in my model's field) shows a red cross (in the admin/superuser dashboard) even if it is by default=True
.