#6095: Add the ability to manually create M2M intermediary models
---------------------------------------+------------------------------------
          Reporter:  jacob             |         Owner:  floguy  
            Status:  reopened          |     Milestone:  1.0 beta
         Component:  Database wrapper  |       Version:  SVN     
        Resolution:                    |      Keywords:          
             Stage:  Accepted          |     Has_patch:  1       
        Needs_docs:  1                 |   Needs_tests:  0       
Needs_better_patch:  1                 |  
---------------------------------------+------------------------------------
Comment (by Rob Hudson <[EMAIL PROTECTED]>):

 It's getting late and I don't have time to test this fully, but I think I
 found a bug.  The only major difference I can see in my case and the
 example is that one of my models is in another app separate from the 2
 models.  For example:

 {{{
 # In myproject/clip/models.py
 class Clip(models.Model):
     title = models.CharField(max_length=200)

 # In myproject/presentation/models.py
 from myproject.clip.models import Clip
 class Presentation(models.Model):
     title = models.CharField(max_length=200)
     clips = models.ManyToManyField(Clip, through='Sequence')
 class Sequence(models.Model):
     presentation = models.ForeignKey(Presentation)
     clip = models.ForeignKey(Clip)
     sequence = models.IntegerField(blank=True, null=True)
 }}}

 The error I'm getting is this:

 {{{
 Traceback:
 File "/Users/rob/sandbox/django/django_trunk/django/core/handlers/base.py"
 in get_response
   86.                 response = callback(request, *callback_args,
 **callback_kwargs)
 File
 
"/Users/rob/sandbox/django/django_trunk/django/contrib/admin/views/decorators.py"
 in _checklogin
   62.             return view_func(request, *args, **kwargs)
 File
 "/Users/rob/sandbox/django/django_trunk/django/contrib/admin/views/main.py"
 in change_stage
   372.         new_data = manipulator.flatten_data()
 File
 "/Users/rob/sandbox/django/django_trunk/django/db/models/fields/related.py"
 in flatten_data
   856.             instance_ids = [instance._get_pk_val() for instance in
 getattr(obj, self.name).all()]
 File
 "/Users/rob/sandbox/django/django_trunk/django/db/models/fields/related.py"
 in __get__
   543.             target_col_name=qn(self.field.m2m_reverse_name())
 File
 "/Users/rob/sandbox/django/django_trunk/django/db/models/fields/related.py"
 in _get_m2m_reverse_name
   829.             return related.field.get_attname_column()[1]

 Exception Type: AttributeError at /admin/presentation/presentation/1/
 Exception Value: 'NoneType' object has no attribute 'field'
 }}}

 Inside the _get_m2m_reverse_name method is this if block.

 {{{
         if self.rel.through is not None:
             meta = related.parent_model._meta
             if self.parent == self.rel.to:
                 related = meta.get_related_object(self.rel.through,
 self_ref = True)
             else:
                 related = meta.get_related_object(self.rel.through)
             return related.field.get_attname_column()[1]
 }}}

 My self.rel.through is 'Sequence' which has a FK to Presentation (the same
 app) and an FK to Clip (different app) plus an integer that's the sequence
 used to order the clips of a presentation.  The meta of the 2nd line if
 printed is 'clip.clip'.  But if I get a Clip object and try to call
 c._meta.get_related_object('Sequence') on it, I get nothing back.  If,
 however, I call the same on a Presentation object, I do get RelatedObject
 back.

 I can supply more details if needed.  Is this supposed to work across
 apps?  Anything I'm doing wrong here?

-- 
Ticket URL: <http://code.djangoproject.com/ticket/6095#comment:65>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to