Ejemplo n.º 1
0
    def update(self, request, id):
        try:
            user = User.objects.get(id=id)
        except User.DoesNotExist:
            return rc.NOT_FOUND

        form = UserForm(request.PUT, request.FILES, instance=user)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()
            return user
        else:
            return form.errors
Ejemplo n.º 2
0
    def create(self, request):
        instance = User()
        form = UserForm(request.POST, instance=instance)

        if form.is_valid():
            user_data = form.save(commit=False)

            user = User.objects.get_or_create(username=user_data.username)[0]
            user.password = user_data.password

            user.save()

            return user

        else:
            return form.errors