我有一个非常简单的ModelResource。
class UserResource(ModelResource):
class Meta:
queryset = CUser.objects.all()
resource_name = 'c_user'
CUser模型如下所示:
class CUser(models.Model):
user = models.OneToOneField(User)
## Some other fields here ##
phone = models.IntegerField()
show_contact_info = models.BooleanField(default=True)
现在我希望查询集包含所有用户,但我想为没有phone
字段设置为show_contact_info
的用户排除True
字段。我怎样才能做到这一点?
答案 0 :(得分:1)
class UserResource(ModelResource):
class Meta:
queryset = CUser.objects.all()
resource_name = 'c_user'
def dehydrate(self, bundle):
if not bundle.obj.show_contact_info:
bundle.data.pop(phone)
return bundle