I have models:
class Article(models.Model):
name = models.CharField(max_length=255)
symbol = models.CharField(max_length=255, unique=True)
. . .
def __unicode__(self):
return '%s (%s)' % (self.name, self.symbol)
class ArticleRel(models.Model):
active = models.BooleanField(default=True)
create = models.DateTimeField(default=datetime.now)
article = models.ForeignKey(Article)
. . .
def __unicode__(self):
return '%s' % (self.id)
and resources:
class ArticleResource(ModelResource):
owner = fields.ForeignKey(UserResource, 'owner')
class Meta:
queryset = Article.objects.all()
resource_name = 'articles'
serializer = Serializer()
authorization = Authorization()
filtering = {
'owner': ALL_WITH_RELATIONS,
}
always_return_data = True
def prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<id>\d+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
]
class ArticleRelResource(ModelResource):
article = fields.ForeignKey(ArticleResource, 'article')
class Meta:
queryset = ArticleRel.objects.all()
resource_name = 'article_rels'
serializer = Serializer()
authorization = Authorization()
filtering = {
'article': ALL_WITH_RELATIONS,
}
always_return_data = True
def prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<id>\d+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
]
and now: how to set this resources so as to get articles with all article_rels in one query?