경우 .. 시간 Tastypie이 데이터를 얻을 수 있지만, 결코 하나의 개체를 업데이트하지의 이미 많이 사용
class IphoneVoteRessource(Resource):
id = fields.IntegerField(attribute='id')
name = fields.CharField(attribute='name')
class Meta:
resource_name = 'poi_vote'
object_class = Row
def obj_update(self, bundle, request=None, **kwargs):
# update an existing row
pk = int(kwargs['pk'])
return bundle `
... obj_get_list 등을 정의 할 필요 작동하는 예제 :
class VoteResourceAnonymous(ModelResource):
class Meta:
queryset = VoteAnonymous.objects.all()
resource_name = 'vote_object'
# need to send 'vote_value' and 'object_id'
excludes = ['created_at', 'content_type', 'content_object', 'user_agent', 'ip_address']
allowed_methods = ['get', 'post', 'put', 'delete']
always_return_data = True
def obj_create(self, bundle, request=None, **kwargs):
vote_value = bundle.data['vote_value']
object_id = bundle.data['object_id']
tmp_poi = PointOfInterestActivity.objects.get(id=object_id)
content_type_object = ContentType.objects.get_for_model(tmp_poi)
bundle.obj = VoteAnonymous(vote_value=vote_value,
object_id=object_id,
user_agent="",
ip_address="",
content_type=content_type_object,
)
bundle.obj.save()
if vote_value > 0:
bundle.data['new_nb_votes'] = tmp_poi.nb_votes + 1
else:
bundle.data['new_nb_votes'] = tmp_poi.nb_votes - 1
return bundle
나는 이처럼 Ressource를 만들려고했지만, 아무런 처리도하지 않아도 작동하지 않습니다. ID = fields.IntegerField (속성 = 'ID') 이름 = fields.CharField (속성 = '이름') 클래스 메타 : 그것은 ... obj_get_list 등 ' 클래스 IphoneVoteRessource (자원)를 정의하는 데 필요한 : RESOURCE_NAME = 'poi_vote' object_class = 행 DEF (자기 번들 요청 = 없음 ** kwargs로) obj_update : # 업데이트 기존 행 PK = INT (kwargs로 [ 'PK']) 복귀 번들 ' 나는 이미 데이터를 얻기 위해 Tastypie를 많이 사용했지만 결코 업데이트하지 않았다. 하나의 물건 ... –