Hi Ram,
I don't have a complete solution for you but I suggest you take a look at the
django.db.models.fields.related.ForeignObject class.
If I'm not mistaken it should allow you to define multi-column relationships
on both your Article and PublisherMediumBilling models and refer to them using
the `select_related()` and `prefetch_related()``API while the later uses Python
to perform in-memory JOINs.
class Article(models.Model):
publisher = ForeignKey(Publisher, related_name='articles')
medium = ForeignKey(Medium)
billing = ForeignObject(
'PublisherMediumBilling', from_fields=['publisher', 'medium'], to_fields=['publisher', 'medium']
)
publisher.articles.select_related('billing')
Cheers,
Simon