On Thu, Feb 19, 2009 at 7:45 AM, madhav <[email protected]> wrote:
> > I have a model something like this: > class CandidateEmailMessage(models.Model): > from_email = models.EmailField(max_length=100) > to_email = models.EmailField(max_length=100) > body = models.TextField() > objects = CandidateEmailMessageManager() > > As the django documentation says blank=False,null=False are there by > default. So if I do > candidate_email_object = CandidateEmailMessage > (from_email='',to_email='',body=''); > candidate_email_object.save() > it should not be saved. But its actually saving, an empty object. I am > running the above script in my test case. How is it actually allowing > that? > Currently validation is only being done at the form level. If you created a ModelForm for this model and tried to specify blanks for those fields the form's is_valid() method would return False and the error messages would indicate that values were required for those fields. But you've not used a form, and we don't yet have model validation, so right now you don't get an error. You might find this post by Malcolm useful if you want to do some validation like this in the absence of built-in model validation in Django: http://www.pointy-stick.com/blog/2008/10/15/django-tip-poor-mans-model-validation/ Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

