如何在Tastype中组合多种资源?我有三个模型,我想结合:用户,个人资料和帖子。在
理想情况下,我希望配置文件嵌套在用户。我想从userpostsresource公开用户和所有配置文件位置。我不知道从这里到哪里去。在
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
fields = ['username','id','date_joined']
#Improper Auth
authorization = Authorization()
class UserProfileResource(ModelResource):
class Meta:
queryset = UserProfile.objects.all()
resource_name = 'profile'
class UserPostResource(ModelResource):
user = fields.ForeignKey(UserResource,'user', full=True)
class Meta:
queryset = UserPost.objects.all()
resource_name = 'userpost'
#Improper Auth
authorization = Authorization()
以下是我的模型:
^{pr2}$
tastype字段(当资源是
ModelResource
时)允许传入attribute
kwarg,后者反过来接受常规的django嵌套查找语法。在因此,首先这可能是有用的:
鉴于上述变化,以下内容:
^{pr2}$将在
UserResource
中公开来自UserProfile
模型的数据。在现在,如果您想在} 方法。在
UserResource
中公开一个位置列表(来自UserPost
),您必须重写其中一个Tastypie
方法。根据文档,一个好的候选方法是^{这样的方法应该有效:
相关问题 更多 >
编程相关推荐