リソース定義、URL オーバーライド、およびカスタム メソッド:
class LocationResource(ModelResource):
create_by = fields.OneToOneField('frittie.app.api.api.UserResource', 'create_by', null=True, blank=True)
follow_by = fields.ToManyField('frittie.app.api.api.UserResource', 'follow_by', null=True, blank=True)
class Meta:
queryset = Location.objects.all()
resource_name = 'Location'
allowed_methods = ['get','post','put','delete']
serializer = Serializer(formats=['json', 'plist'])
# authorization= DjangoAuthorization()
def override_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<%s>[\w/-]*[\w-])%s$/follow_by%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_follow'), name="api_get_follow"),
]
def obj_create(self, bundle, request=None, **kwargs):
username, email, password = bundle.data['username'], bundle.data['password'], bundle.data['password'],
try:
bundle.obj = User.objects.create_user(username, email, password)
except IntegrityError:
raise BadRequest('That username already exists')
return bundle
def get_follow(self, request, **kwargs):
basic_bundle = self.build_bundle(request=request)
obj = self.cached_obj_get(bundle=basic_bundle, **self.remove_api_resource_names(kwargs))
user_resource = UserResource()
return user_resource.get_list(request, location =obj )
このリンクを開こうとしましたが、保持されます:
"error_message":Invalid resource lookup data provided (mismatched type).
localhost/api/frittie/Location/1/follow_by/?username=itams& api_key=42cc8665811e121edbbd57ceee90c1373da2f60
私のAPI実装で何が間違っているか教えてもらえますか