You could create a model that references the join table itself.

class ArticlePublicationsJoin(models.Model):
    id = models.AutoField()
    publicaiton_id = models.IntegerField()
    article_id = models.IntegerField()
    class Meta:
        db_table = 'article_publications'

then just query on that...

query = ArticlePublicationsJoin.objects.get(publication_id='pub_id',
article_id='art_id')
primary_key = query.pk


On Apr 22, 7:13 pm, Info Cascade <informationcasc...@gmail.com> wrote:
> Hi --
>
> I have two models with a m2m relationship, and I need to get the value
> of the primary key of the join table.
>
> To use the example from the book:
>
>
>
>
>
> > from django.db import models
>
> > class Publication(models.Model):
> >     title = models.CharField(max_length=30)
>
> >     def __unicode__(self):
> >         return self.title
>
> >     class Meta:
> >         ordering = ('title',)
>
> > class Article(models.Model):
> >     headline = models.CharField(max_length=100)
> >     publications = models.ManyToManyField(Publication)
>
> >     def __unicode__(self):
> >         return self.headline
>
> >     class Meta:
> >         ordering = ('headline',)
>
> Django creates the article_publications join table automatically.
>
> What I need is, for a particular combination of article and publication,
> what is the primary key in the join table?
>
> Any thoughts?
>
> Please Cc: me at liamk -- AT -- numenet --DOT--com if you can help!
>
> Thanks,
> Liam
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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