Hey Collin, I had no problem in the shell...
In [4]: AffectedPart.objects.all().count() Out[4]: 4090 # pick a random AffectedPart In [5]: affpart = AffectedPart.objects.all()[22] In [6]: affpart.damage_types.all() Out[6]: [<DamageType: Dent>] I'm not sure why this doesn't work running under the server. My models look like this: from sitar.models import (Part, DamageType, Aircraft) # this model is in trending.modelsclass AffectedPart(models.Model): res = models.ForeignKey(Res, null=True) arising = models.ForeignKey(Arising, null=True) aircraft = models.ForeignKey(Aircraft) # filled out automatically only if part to Damage/Repair type matching done maintenance_phase = models.CharField(max_length=10, choices=MAINTENANCE_PHASE_CHOICES) occurrence_date = models.DateField() partnumber = models.ForeignKey(Part) damage_types = models.ManyToManyField(DamageType, null=True, blank=True) repair_types = models.ManyToManyField(RepairType, null=True, blank=True) def __unicode__(self, ): if self.res: parent = self.res.number else: parent = str(self.arising) return '{0} - {1}'.format(self.partnumber.number, parent) # The following models are in sitar.models class Part(models.Model): ''' This model is used to create pick-lists so the user can associate one or more applicable parts from a pre-defined list to a tracked item. It will also allow for regular CRUD functionality which is implemented by taking advantage of the Django admin interface. ''' # Added to associate a zone with a part zones = models.ManyToManyField("Zone", null=True, blank=True) number = models.CharField(max_length=50, unique=True) description = models.CharField(max_length=100, blank=True) comments = models.TextField(blank=True) material = models.CharField(max_length=100, blank=True) class Meta: ''' Order by part number field (ascending) when presenting data ''' ordering = ['number'] def __unicode__(self): ''' Return unicode description of a part instance ''' if self.description: return '%s -- %s' % (self.number, self.description) else: return self.number def get_encoded_part_number(self): ''' This method will remove any '/' in part numbers and replace them with '~' so that they can be used in URLs. ''' return self.number.replace('/','~') class DamageType(models.Model): description = models.CharField(max_length=50, unique=True) # a regular expression to account for possible spelling mistakes when # querying the database reg_exp = models.CharField(max_length=50, blank=True) # Added to provide damage code for TRENDING cgs_damage_code = models.CharField(max_length=10, blank=True, verbose_name="CGS Damage Code") def __unicode__(self): ''' Return unicode representation of a DamageType instance. ''' return self.description class Meta: ''' Order by description field (ascending) when presenting data ''' ordering = ['description'] def save(self): ''' Override the save method of the DamageType model in order to assign a regexp if one does not exist.''' # if the tracked item does not have a reg_exp just use # the description if not self.reg_exp: self.reg_exp = self.description super(DamageType,self).save() /Paul On Tuesday, October 21, 2014 12:52:45 PM UTC-3, Collin Anderson wrote: > > Hi Paul, > > Interesting. Your code should work fine. So if you run this code in the > shell it gives a FieldError? > > affpart.damage_types.all() > > What do your sitar models look like? There should not be a ManyToManyField > in the other direction. > > Collin > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0a43b7fb-4937-4a41-b519-0134cd64a01f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.