Prevent field from becoming null

31 views
Skip to first unread message

Samuel Muiruri

unread,
Dec 10, 2015, 8:26:00 AM12/10/15
to Django users
Hello,
I want to override the save for the show model so I check for if the value passed for a field is null if so ignore saving for the field

class Shows(models.Model):
    some_field = models.CharField(max_length=128, default="something")
    def save(self, *args, **kwargs):
        super(Show, self).save()


monoBOT

unread,
Dec 10, 2015, 12:32:26 PM12/10/15
to django...@googlegroups.com
The default is simply the default value, the user can still delete it.

You can control how the user enters the values in the form, in particular on the clean_atribute method or redefining the clean one inherited from  the forms.ModelForm class

If your want to be "hacky" you can rewrite the save method in the model and there control if what the user enters is not of your appeal, but then you are cheating arent you?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c31be361-21f1-45c9-8257-78b56bf45c78%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
monoBOT
Visite mi sitio(Visit my site): monobotsoft.es/blog/
Reply all
Reply to author
Forward
0 new messages