Just an idea, not sure if it will work for you as I don't know a whole lot
about how it works, but wouldn't setting unique_together on the Relation
class for owner and pet accomplish what you want?  The validation happens at
the DB level, but I believe it propogates back to the form.
hth,
-richard



On 6/11/08, Adi <[EMAIL PROTECTED]> wrote:
>
>
> Right.. I do that for setting the foreign key..
> But I want to know how to do form validation when I need a related
> model object inside the validation logic.
>
> On Jun 11, 12:29 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
> > on a modelform you can do: form.save(commit=False), which will return
> > an instance of the model, but doesn't save it to the db, so you can
> > just assign request.user to owner and than save it.
> >
> > On Jun 11, 12:07 am, Adi <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > I guess... the more deeper question is.. how can I pass a related
> > > model object and potentiall an unrelated model object into the form's
> > > validations methods?
> >
> > > On Jun 10, 10:42 pm, Adi <[EMAIL PROTECTED]> wrote:
> >
> > > > Hi,
> > > > I have a model  Owner and a model Relation.
> >
> > > > class  Relation(models.Model):
> > > >     pet=models.CharField(max_length=2)
> > > >     owner = models.ForeignKey (Owner)
> >
> > > > then I have a ModelForm
> >
> > > > class RelationForm(ModelForm):
> > > >    class Meta:
> > > >        fields  = ('pet')
> >
> > > > The application flow works like this: You create a Relation object
> > > > within the context of an Owner Object. There is a rule that says that
> > > > a owner cannot have two Relation with the same pet value. How can I
> > > > create a validation on the form that can check this rule. Basically,
> > > > How can i pass owner object that I have in the view when I call
> > > > RelationForm.is_valid()
> >
> > > > -Adi- Hide quoted text -
> >
> > - Show quoted text -
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to