1

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
4

1 回答 1

2

是的,这是 Tastypie 的一种奇怪行为。但fields = ['']也可以。

于 2013-01-30T09:13:33.657 回答