User和UserProfile与'OneToOneField'
相关我有fields = []来抑制脱水方法中列出的所有其他字段,
但它不起作用。(显示UserProfile模型中的所有字段)
class UserProfileResource(ModelResource):
user = fields.OneToOneField(UserResource, 'user')
class Meta:
queryset = UserProfile.objects.all()
fields = [] ## here, this doesn't work as intended
def dehydrate(self, bundle):
bundle.data['username'] = bundle.obj.user.username
bundle.data['id'] = bundle.obj.user.id
bundle.data['url_profile_image'] = bundle.obj.url_profile_image # this is a property call
bundle.data['url_profile_image_thumbnail'] = bundle.obj.url_profile_image_thumbnail
return bundle
答案 0 :(得分:2)
是的,这是Tastypie的奇怪行为。但fields = ['']
也适用。