[Django]-Check if a non-nullable field is null

10👍

Check if it has the attribute set –

if hasattr(self, 'field')
👤gone

0👍

proper way to refer a field in form is like this:
self.fields['myfield']
so, in your case, the null check should go like this
self.fields['myfield'].value is None

on the other note, don’t use reserved/near to reserved words like ‘field’ for naming your fields.

Leave a comment