0

我有一个非常简单的 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。我怎样才能做到这一点?

4

1 回答 1

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
于 2013-02-18T09:57:55.403 回答