Hi,

I have the following models:

class Memory(models.Model):
    partnum = models.CharField(max_length=30)
    size = models.IntegerField()

    def __unicode__(self):
        return self.partnum

class Motherboard(models.Model):
    name = models.CharField(max_length=20)
    sockets = models.IntegerField()
    modules = models.ManyToManyField(Memory, through='MemModules')

    def __unicode__(self):
        return self.name

class MemModules(models.Model):
   memory = models.ForeignKey(Memory)
   motherboard = models.ForeignKey(Motherboard)
   count = models.IntegerField()

I can use the following statements to access the memory items for a
particular motherboard:

>>> from mike.test.models import *
>>> m = Motherboard.objects.get(name="C7X58")
>>> print m.name
C7X58
>>> print m.modules
<django.db.models.fields.related.ManyRelatedManager object at
0x9763f6c>
>>> mods = m.modules.all()
>>> print mods
[<Memory: ACT1GHU64B8F1333S>, <Memory: ACT2GHU64B8F1333S>]
>>> for i in mods:
...    print i.partnum
...
ACT1GHU64B8F1333S
ACT2GHU64B8F1333S

My question is:  How do I access the extra fields stored in my custom
intermediate table?  In this case that would be the count field.  I
have search the Django documentation but so far I haven't found any
examples.

Thanks for any help!

Mike

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to