做一個獲取(TastyPie)我收到以下錯誤:「CompanyUser」對象有沒有屬性「所有」
error_message": "'CompanyUser' object has no attribute 'all'", /resources.py\", line 832, in full_dehydrate\n bundle.data[field_name] = field_object.dehydrate(bundle, for_list=for_list)\n\n File \"/Users/user/Documents/workspace/membergetmember/django-env/lib/python2.7/site-packages/tastypie/fields.py\", line 818, in dehydrate\n for m2m in the_m2ms.all():\n\nAttributeError: 'CompanyUser' object has no attribute 'all'\n"
從我的理解這應該工作,我做了什麼錯?下面的代碼。
class UserResource(ModelResource):
class Meta:
queryset = get_user_model().objects.all()
resource_name = 'CompanyUser'
class CampaignCreateResource(ModelResource):
user = fields.ToManyField(UserResource, 'user', full=False)
class Meta:
queryset = Campaign.objects.all()
resource_name = 'campaign'
allowed_methods = ['post', 'get']
authentication = APIAuthentication().get_authentication()
authorization = UserObjectsOnlyAuthorization()
validation = FormValidation(form_class=CampaignForm)
excludes = ['id']
型號
class Campaign(models.Model):
name = models.CharField(max_length=60, help_text="Give your campaign a name i.e Xmas Offer")
user = models.ForeignKey(get_user_model(), related_name='user', null=True)
什麼版本的Django? – mconlin
@mconlin使用1.5.x版本和AUTH_USER_MODEL ='accounts.CompanyUser' – GrantU
如果您使用queryset = CompanyUser.objects.all(),但您想按照預期使用身份驗證善良性,則我認爲它可以正常工作... – mconlin