示例#1
0
def register(request):
    if request.method == "POST":
        form = RegistrationForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data

            new_customer = Customer()

            # Stock django User model fields
            new_customer.username = data['id_number']
            new_customer.set_password(data['password'])
            new_customer.first_name = data['first_name']
            new_customer.last_name = data['last_name']
            new_customer.email = data['email']

            # Our custom properties
            new_customer.phone_number = data['phone_number']
            new_customer.address = data['address']

            new_customer.save()

            return HttpResponseRedirect(reverse("register_thanks"))
    else:
        form = RegistrationForm()

    return render(request, "users/register.html", {"form": form})
示例#2
0
    def save(self, commit=True):
        cleaned_data = self.cleaned_data
        instance = super().save(commit=False)
        instance.set_password(self.cleaned_data.get('password'))
        instance.save()
        client = Customer(user=instance)
        address = cleaned_data.get('address')
        if address:
            client.address = address
        avatar = cleaned_data.get('avatar')
        if avatar:
            file = Image(file=avatar,
                         owner=instance,
                         name=avatar.name,
                         original_filename=avatar.name)
            file.save()
            instance.image = file
        client.save()
        instance.save()

        return instance