Ok, so I believe I'm following the documentation properly for a
ManyToManyField with the Through=xxx option here:
http://docs.djangoproject.com/en/dev/ref/models/fields/#manytomanyfield

class Pessoa(models.Model):
    Nome        = models.CharField('Nome', max_length=100)
    Localidade  = models.CharField('Moradas', max_length=200)

    ** Snip **

    def __unicode__(self):
        return self.Nome + ' (' + self.Localidade + ')'

class Matriz(models.Model):
    NumOrd        = models.IntegerField('NĂºmero de ordem (artigo da
matriz)',
        primary_key=True)

    ** Snip **

    Proprietarios = models.ManyToManyField(Pessoa,
through='MatrizPropri')

    ** Snip **

    def __unicode__(self):
        return unicode(self.NumOrd) + ' - ' + self.SitPredios

class MatrizPropri(models.Model):
    NumOrd     = models.ForeignKey(Matriz)
    Pessoa     = models.ForeignKey(Pessoa)
    PrimerioFg = models.BooleanField(default=False)

    ** Snip **

    def __unicode__(self):
        return unicode(self.Pessoa) + ' (Primerio: ' + unicode
(self.PrimerioFg) + ')'


Then I setup the admin using an Inline class to manage the
MatrizPropri model within the Matriz change form:

class MatrizPropriInline(admin.TabularInline):
    model = MatrizPropri
    extra = 1

class MatrizAdmin(admin.ModelAdmin):
    inlines = [MatrizPropriInline]

admin.site.register(Matriz, MatrizAdmin)


My problem is that I get an error in regards to the Pessoa_id in
MatrizPropri. I pulled the following out of the MySQL sql.log:

SELECT `matriz_matriz`.`NumOrd`, `matriz_matriz`.`SitPredios`,
`matriz_matriz`.`Ano`, `matriz_matriz`.`Descricao`,
`matriz_matriz`.`Rendimento`, `matriz_matriz`.`RendTypoCD`,
`matriz_matriz`.`Observacoes`, `matriz_matriz`.`MdUsr`,
`matriz_matriz`.`MdDT`, `matriz_matriz`.`CrUsr`,
`matriz_matriz`.`CrDT` FROM `matriz_matriz` INNER JOIN
`matriz_matrizpropri` ON (`matriz_matriz`.`NumOrd` =
`matriz_matrizpropri`.`NumOrd_id`) WHERE
`matriz_matrizpropri`.`Pessoa_id` =
'<django.db.models.fields.related.ManyRelatedManager object at
0x016B1130>'  ORDER BY `matriz_matriz`.`_order` ASC LIMIT 21


Obviously the Pessoa_id value in the where clause is wrong. How can I
fix it?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to