On 06/25/06 16:58, Malcolm Tredinnick wrote: > On Sun, 2006-06-25 at 22:39 +0800, Russell Keith-Magee wrote: >> On 6/25/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: >> > >> > I'd like to draw some attention to ticket >> > http://code.djangoproject.com/ticket/2232 (mainly russelm's attention as >> > it appeared after his checkin 3195). >> >> Paying attention now :-) >> >> > Basically ManyToMany relations don't work when you try to get related >> > queryset from a model where ManyToManyField is defined. Or is it just me? >> >> For me, all the regression tests passed at time of checkin. Following >> the rest of the messages on this thread, it looks like the problems is >> with model importing. 2 quick observations which might help find the >> problem: >> >> 1) r3195 did make some changes to the model importing process, so this >> might have changed the conditions under when any previous __import__ >> related bug revealed itself >> >> 2) I have seen the behaviour from r1796 before - for me, the problem >> ultimately turned out to be caused by a PYTHONPATH that included the >> application directory (so "from myapp.models import Foo" and "from >> myproject.myapp.models import Foo" were both legal). At the time, I >> chalked it up to the pythonpath, and moved on (sorry - can't give any >> more specific details as to SVN revision, exact code structure, etc). >> >> I don't know if this helps anyone - however, I thought it might yield >> a reliably broken test case. > > I've just checked in r3202 which I believe fixes the root cause of #1796 > in a reasonably correct way. I think it also fixes #2232 for the same > reason. It all seems to come down to the import paths being used as > dictionary keys and models being registered twice. See the change for > the way I am working around this. > > Russ: can you see if I've overlooked any problem there, please. It took > a little while to track everything down and my brain may have gotten > twisted in the process. Also, I left it alone for now and I realise you > were just cutting-and-pasting, but __import__ takes dictionaries as the > second and third arguments (globals() and locals(), basically, although > the third arg is essentially ignored); why are we passing in strings??? > > I can no longer cause #1796 or anything like it to fail -- and I had a > couple of failing examples there. I believe relative imports > (appname.models, etc) might now work reliably too (experiments suggest > they do), which means you no longer are reliant on your project name and > can create portable apps. > > Feedback welcome/appreciated. I may have screwed up in some subtle way. > > Regards, > Malcolm >
I also had some problems related to this and started writing the mail below. But before sending it I noticed that you had checked something in, did an svn up, and my problem went away. I don't know or understand how/where/if my problem and #2232/#1796 are really related, but it seems your checkin also solved my problem. Just posting this here as a FYI. Thanks for the fix :D best regards Steven ---------- backward relationships for Many-to-many don't work for optional fields? Given the following models class Artist(models.Model): first_name = models.CharField(maxlength=30) last_name = models.CharField(maxlength=30) class Event(models.Model): name = models.CharField(maxlength=255) artists = models.ManyToManyField(Artist, blank=True, null=True) Forward relationship is ok: >>> event = Event.objects.all()[0] >>> event.artists <django.db.models.fields.related.ManyRelatedManager object at 0xb795128c> But the backward relationship API is not created/available: >>> artist = Artist.objects.all()[0] >>> artist.event_set AttributeError: 'Artist' object has no attribute 'event_set' If I change the artists field in the Event model to be required, backward relationship starts working: class Event(models.Model): name = models.CharField(maxlength=255) # artists is now a _required_ field artists = models.ManyToManyField(Artist) >>> artist = Artist.objects.all()[0] >>> artist.event_set <django.db.models.fields.related.ManyRelatedManager object at 0xb74bf88c> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@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-developers -~----------~----~----~----~------~----~------~--~---