I have the following model in django.
class Link(models.Model): name = models.CharField(max_length=100) url = models.CharField(max_length=100) tag = models.CharField(max_length=100) def __unicode__(self): return self.name
I need the url field to be optional. How do I do this?
You would have to add blank=True as well in field definition. If the model field has blank=True, then required is set to False on the form field. Otherwise, required=True. Don't forget to reset and sync DB again after changing this.
How to use required in Django Form field? required is often used to make the field optional that is the user would no longer be required to enter the data into that field and it will still be accepted.
Add the attribute blank=True
. Optionally, you can also make the field NULLable with null=True
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With