Re: How can I apply constraints on model relationships?

2009-01-09 Thread Malcolm Tredinnick

On Fri, 2009-01-09 at 04:06 -0800, rabbi wrote:
> Hi Malcolm,
> Filtering out all the Animals that satisfy that constraint is easy...
> even for a noob like me :)
> 
> What I want is for that constraint to be enforced as/before the data
> is inserted as I have a few complex (by my standards) relationships
> that would benefit from that sort of functionality.
> I can always write business logic to handle this in the actual app,
> but I was hoping that functionality was available so I'd have
> something to fall back on.
> I'm the only one who will have admin rights so it's no problem from
> that point, as long as I'm careful when inserting data.

Okay. So the solution is "wait a little bit longer". We're working on
it. :-)

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How can I apply constraints on model relationships?

2009-01-09 Thread rabbi

Hi Malcolm,
Filtering out all the Animals that satisfy that constraint is easy...
even for a noob like me :)

What I want is for that constraint to be enforced as/before the data
is inserted as I have a few complex (by my standards) relationships
that would benefit from that sort of functionality.
I can always write business logic to handle this in the actual app,
but I was hoping that functionality was available so I'd have
something to fall back on.
I'm the only one who will have admin rights so it's no problem from
that point, as long as I'm careful when inserting data.

Thanks

On Jan 9, 1:00 pm, Malcolm Tredinnick 
wrote:
> On Fri, 2009-01-09 at 03:33 -0800, rabbi wrote:
> > Is there a way to specify a constraint on a model ManyToMany
> > relationship?
>
> > For example, if I wanted to define an Animal model that has a field
> > which specifies which other animals it eats and I wanted to limited
> > these animals_I_eat relationships to animals who's specie_name starts
> > with "x", how would I do this?
>
> > E.g.
>
> > class Animal(models.Model):
> >     specie_name = models.CharField(max_length=50)
> >     animals_I_eat = models.ManyToManyField('self',blank=True)
> > #where animals_I_eat.specie_name starts with "x"
>
> > This is probably a very bad example, but I hope you get what I'm
> > trying to say
>
> Do you want this constraint to be enforced for every piece of data that
> is inserted? If so, you can't do that yet (sorry!). It requires what
> we're calling model-aware validation, at a minimum, and that's something
> that we're working on for Django 1.1 (in fact, right this minute, I'm
> reviewing some of that code). Essentially, that means form-like
> validation for models.
>
> Or are you asking how to filter out all the Animals that satisfy that
> constraint?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How can I apply constraints on model relationships?

2009-01-09 Thread Malcolm Tredinnick

On Fri, 2009-01-09 at 03:33 -0800, rabbi wrote:
> Is there a way to specify a constraint on a model ManyToMany
> relationship?
> 
> For example, if I wanted to define an Animal model that has a field
> which specifies which other animals it eats and I wanted to limited
> these animals_I_eat relationships to animals who's specie_name starts
> with "x", how would I do this?
> 
> E.g.
> 
> class Animal(models.Model):
> specie_name = models.CharField(max_length=50)
> animals_I_eat = models.ManyToManyField('self',blank=True)
> #where animals_I_eat.specie_name starts with "x"
> 
> This is probably a very bad example, but I hope you get what I'm
> trying to say

Do you want this constraint to be enforced for every piece of data that
is inserted? If so, you can't do that yet (sorry!). It requires what
we're calling model-aware validation, at a minimum, and that's something
that we're working on for Django 1.1 (in fact, right this minute, I'm
reviewing some of that code). Essentially, that means form-like
validation for models.

Or are you asking how to filter out all the Animals that satisfy that
constraint?

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---