Wednesday 27 May 2020

Django - Make field not required

The solution for this was fairly simple but I had to search for a fair bit.  

Hopefully this will help someone else out. 

In your 'model.py' of the App you're working on you need to make this one simple change. 

I had 

width = models.CharField(max_length=5)


Which I added 

width = models.CharField(max_length=5, null=True, blank=True)

You'll also need to run the migrates again .  So 

python manage.py makemigrations YOURAPPNAME


Python manage.py migrate


You should now see that there's no asterix against this field on the form and that you can save a Null value. 

No comments: