Re: Accessing related objects on model.clean()
On Wed, Oct 16, 2013 at 11:52 PM, Marc Aymerich <glicerinu@gmail.com> wrote:
> Yep,
> I'm writing some validation logic for a model that is being used in an
> admin inline form
>
> The model looks like this
>
> class Child(models.Model):
> parent = models.ForeignKey(Parent)
>
> def clean(self):
> super(....).clean()
> if self.parent.surname != self.surname:
> raise ValidationError....
>
> The problem is that on the "Parent add admin view" I get a
> Parent.DoesNotExist error when I'm saving new Parent and Childs. That
> is because when child.clean() is called child.parent_id is None, so
> self.parent fails, it looks like self.parent is created afterwards and
> is not available at that time.
yep this was something related with my application ! it is indeed
possible to access related objects on model clean, sorry for the
noise!
--
Marc
--
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%2BDCN_ucGB4yM%3Dqr5NkBT8Dk1Wmd1zkzeXaFQ%3DofSpvnwJFWAw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home