#13155: Iteration of a Many To Many Relationship raises Field Error
---------------------------------------------------+------------------------
          Reporter:  callen                        |         Owner:  nobody     
          
            Status:  reopened                      |     Milestone:             
          
         Component:  Database layer (models, ORM)  |       Version:  1.1        
          
        Resolution:                                |      Keywords:  m2m, orm, 
field error
             Stage:  Unreviewed                    |     Has_patch:  0          
          
        Needs_docs:  0                             |   Needs_tests:  0          
          
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by callen):

 Replying to [comment:5 kmtracey]:
 > What is the variable bimport? Guessing the obvious -- that it is an
 instance of Bimport -- I cannot recreate the problem:
 >
 > {{{
 > >>> from ttt.models import Bimport
 > >>> bimport = Bimport.objects.all()[0]
 > >>> bimport.newsletters.all()
 > [<Newsletter: Newsletter object>]
 > >>> import django
 > >>> django.get_version()
 > u'1.2 beta 1 SVN-12805'
 > >>> for nl in bimport.newsletters.all():
 > ...     print nl.name
 > ...
 > first
 > >>>
 > }}}

 You're correct that bimport is just a Bimport instance. As I said, the
 issue cannot be reproduced in a shell because it works for me as well.

 {{{
 In [1]: from bimport.models import Bimport

 In [2]: bi = Bimport.objects.get(id = 20)

 In [3]: for nl in bi.newsletters.all():
    ...:     print nl
    ...:
 Soccer America Classifieds
 Youth Soccer Insider
 }}}

 I can do that too. However, when it's running in the actual web app:

 {{{
 ipdb>
 >
 /Users/callen/code/socceramerica/bimport/controllers.py(36)process_bimport()
      35         bi.save()
 ---> 36         if int(bi.content_type.id) == 116:
      37             code = import_subs(bi)

 ipdb>
 >
 /Users/callen/code/socceramerica/bimport/controllers.py(37)process_bimport()
      36         if int(bi.content_type.id) == 116:
 ---> 37             code = import_subs(bi)
      38             if code == 1:

 ipdb> bi
 Out[0]: <Bimport: Bimport object>

 ipdb> pdoc bi
 Bimport(id, content_type_id, source_id, import_date, datafile, error,
 status)

 ipdb> pinfo bi
 Type:           Bimport
 Base Class:     <class 'bimport.models.Bimport'>
 String Form:    Bimport object
 Namespace:      Locals
 File:           /Users/callen/code/socceramerica/bimport/models.py
 Source:
 class Bimport(models.Model):
     content_type = models.ForeignKey(ContentType)
     source = models.ForeignKey(Source)
     import_date = models.DateField(auto_now_add = True)
     datafile = models.FileField(upload_to='bimport/uploads')
     newsletters = models.ManyToManyField(Newsletter, help_text=None,
 null=True)
     error = models.CharField(max_length=200)
     status = models.CharField(choices=STATUS_CHOICES, default='N',
 max_length=100)

 ipdb> bi.newsletters.all()
 *** FieldError: Cannot resolve keyword 'bimport' into field. Choices are:
 archive_column, archive_order, article, construct, day, edition,
 frequency, frequency_text, from_email, html_template, id, is_public,
 list_name, name, newsletterarticle, newsletterarticles, slug, subject,
 subject_type, subscription, text_template, time
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13155#comment:6>
Django <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