我有型號:如何獲取相關資源?
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)
和資源:
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"),
]
現在:如何設置這個資源,從而在一個查詢中的所有article_rels得到物品?