Monday, February 10, 2014

Re: I'm getting obsessed! Where should I put this code?

Thank you so much for all your comments, they were very helpful.

After reading 'a lot' I think I've found some calm.

I decided to move all validation into validation.py. I then used these functions in both forms and the models i.e.

mobile = PhoneNumberField(validators=[validate_mobile])

I found that Django however, does not call the clean method by default when saving a model.

I got rid of the signal pre_save I read it was a bad idea! I found that the save() method is executed at the same time the `pre_save` -signal was.

    def save(self, force_insert=False, force_update=False, *args, **kwargs):
        """
        Override of save() method which is executed the same
        time the ``pre_save``-signal would be
        """
        if not (force_insert or force_update):
            self.full_clean()

I feel a lot better now :)

--
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/1f3b54d4-242b-4d20-ad88-bb52b4316d37%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment