def update(cls, username, metadata): user = User.objects.get(username=username) fields = metadata.keys() for field in fields: setattr(user, field, metadata[field]) user.save() response = instance_to_dict(user, UserApi.base_field) return Response(asjson.dumps(response), mimetype='application/json')
def get(cls, username): user = User.objects.get(username=username) response = instance_to_dict(user, UserApi.base_field) return Response(asjson.dumps(response), mimetype='application/json')
def create(cls, metadata): user = User(**metadata).save() response = instance_to_dict(user, UserApi.base_field) return Response(asjson.dumps(response), mimetype='application/json')
def index(cls): users = User.objects.all() # we used wrapper "instance_to_dict" for select by based field model response = [instance_to_dict(user, UserApi.base_field) for user in users] return Response(asjson.dumps(response), mimetype='application/json')