On Mon, 2008-04-14 at 08:23 -0700, Michael Newman wrote:
> Imagine:
> 
> from django.db import models
> 
> class Mtmfield(models.Model):
>     afield = models.TextField()
> 
> class Place(models.Model):
>     somefield = models.ManyToManyField(Mtmfield,
> related_name='a_name_that_cant_have_conflicts')
> 
>     class Meta:
>         abstract = True
> 
> class Restaurant(Place):
>     someotherfield = models.TextField()
> 
> class Bar(Place):
>     somethirdfield = models.TextField()

[...]
> This only seems to occur when there is a ManyToManyField in the
> abstract base class and there are 2 items that extend that base class.
> This does not seem to be a problem when the base class is not
> abstract. This also occurs in MySQL.
> 
> I would like to open a ticket, but wanted to just make sure that I am
> implementing the abstract base classes in the way that they were
> designed. I would also like to help out with a patch, but can't even
> begin to figure out where the issue is coming from.

Hmm ... I suspect you're doomed there, in that there's no easy solution
here. The requirement is that all reverse relations must have unique
names. And if you have a Mtmfield instance and try to access the
"a_name_that_cant_have_conflicts" attribute, it's not going to be
unique.

So I think it's a case of "don't do that". Django's default name will be
unique for most simple cases (you're forcing the disaster here by
specifying the related name). In complex cases -- such as multiple
many-to-many fields on the same abstract base class that relate to the
same model -- it might just not be possible. It's not going to be
particularly easy to be add something that allows dynamic related name
generation, since it has to be both completely predictable to the code
using those model and executable at import time.

I'll think about it a bit, but at the moment I'm inclined to think it's
not worth building in that type of complex API just for this type of
case. In these cases you'll just need to write out the fields on the
base models and given them their own unique related names. Life's like
that sometimes; it's a clash between not having to annotate both ends of
a relation and still being able to traverse it both ways (requiring
unique names), and wanting to reuse a field declaration multiple times
(meaning all the information is the same).

Regards,
Malcolm

-- 
On the other hand, you have different fingers. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to