Hi --

I have a question about many-to-many relationships and how to reference
a related object field using Django syntax via the Manager class.
I think this is probably pretty simple and just reflects my inexperience
working with Django (which overall I am enjoying, btw.)
Anyway, the models look  like this:

class Poi(models.Model): # A "Point of Interest"
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=1024, null=False, db_index=True)
    articles = models.ManyToManyField('Article', null=True,
db_table='poi_articles')

class PoiRank(models.Model):
    poi = models.OneToOneField(Poi, primary_key=True)
    rank = models.IntegerField(null = False, blank = False)

class Article(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=1024, blank=True, db_index=True)
    pois = models.ManyToManyField(Poi, null=True, db_table='poi_articles')
    status = models.CharField(max_length=27, blank=True)


One Poi can have many Articles written about it.  One Article can be
referenced by many Poi's.
A Poi has 0 or 1 "rank" value which is some measure of its popularity.

Now, I had to set the db_table name to poi_articles because otherwise I
ended up with what were essentially duplicate tables (just with the
order of the foreign keys swapped).
Of course, doing that I then had to remove the duplicate poi_articles
table that got generated the first time I ran syncdb.
This makes me think that I may not have set things up correctly in the
first place.

Anyway, after doing a query I have a QuerySet of articles.  I need to
know that the rank of the article is.  That's all.  It should be simple,
right?

The following SQL give the expected result if I enter it directly:
SELECT p.title, a.status, pr.rank FROM article a
INNER JOIN poi_articles ON a.id = poi_articles.article_id
INNER JOIN poi p ON poi_articles.poi_id = p.id
INNER JOIN poi_rank pr ON pr.poi_id = p.id
WHERE a.id = 803827;

But, how do I create that query using Django syntax and the Manager?

Any help will be very much appreciated!

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-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