Thursday, December 10, 2015

Re: Prevent field from becoming null

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?

2015-12-10 13:26 GMT+00:00 Samuel Muiruri <muiruri.samuel@gmail.com>:
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()


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CA%2BxOsGCOqRrXxKEfDZM5Lome8cxLGcmUX3cwoo18BD1f%3DP1UAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment