0

I have my models defined as:

class MyUser(AbstractUser):
    created = models.DateTimeField(auto_now_add=True)
    name = models.CharField(max_length=256)
    phone = models.IntegerField()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username', 'name', 'phone']

MyUser._meta.get_field_by_name('email')[0]._unique=True

now when I am calling create_user by sending all the arguments in the form my view.py looks like

def new_user(request):
    email = request.POST.get('email','')
    phone = request.POST.get('phone','')
    name = request.POST.get('name','')
    password = request.POST.get('password','')
    confirm_pass = request.POST.get('confirm_password','')
    if password and confirm_pass and password == confirm_pass:
        try:
            user = MyUser.objects.get(email=email)
        except MyUser.DoesNotExist:
            user = None
        if user:
            message = 'User with the following email id already exists'
            return render(request, 'signup.html', {'message':message})
        else:
            user = My.objects.create_user(email, email, name, phone, password)
            user.save()
            login(request, user)
            return render(request, 'details.html', {'username':request.user.username})
    else:
        message = 'Paaswords does not match each other'
    return render(request, 'signup.html', {'message':message})

Now each time this function executes it shows me the following error

create_user() takes at most 4 arguments (6 given)

I could'nt understand why is create_user not working.

saurabh
  • 293
  • 2
  • 7
  • 19

2 Answers2

0

create_user function takes the parameters as *args, so you need to call the function like that:

create_user(email = email, name = name, phone = phone, password = password)

or easily pass your request.POST:

create_user(request.POST)

I'm seeing that your view is a little bit complex, have you ever try Class Based Views? With class based views you can create method do deal with get querysets and form rendering. That a look https://docs.djangoproject.com/en/dev/topics/class-based-views/

At last advice, you can create a register_form to deal with data validation: https://docs.djangoproject.com/en/dev/topics/forms/

0

You're sending 6 arguments from your views.py where as you have only 4 required. Note that password and confirm pass count as your 2 additional arguments. That's what I think anyway

Take a look at THIS example. It helped me with creating my abstract user.

If you'd like some code examples, HERE is a good breakdown (if you're on Django 1.5 that is)

Hevlastka
  • 1,878
  • 2
  • 18
  • 29
  • there are 5 fields which I am sending first email as email, second email as username, third name as name, fourth as phone and last as password I mean I am just sending all the required fields – saurabh Feb 11 '14 at 16:42
  • the examples you gave are for abstractbaseuser and mine in abstractuser – saurabh Feb 11 '14 at 16:46