User 和 UserProfile 与“OneToOneField”相关
我有 fields = [] 来抑制 dehydrate 方法中列出的所有其他字段,
但它不起作用。(显示 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