Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

optional fields in django models

Tags:

django

model

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?

like image 410
eatonphil Avatar asked May 02 '13 23:05

eatonphil


People also ask

How do I make a field optional in Django?

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.

What is required field in Django model?

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.


1 Answers

Add the attribute blank=True. Optionally, you can also make the field NULLable with null=True.

like image 154
mipadi Avatar answered Sep 19 '22 03:09

mipadi