Hi all,
I am trying to create the django application with new django version 2.2.3, I am getting the
TypeError at /signup/
__init__() got an unexpected keyword argument 'instance'
models.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, UserManager, PermissionsMixin
# Create your models here.
class MyUser(AbstractBaseUser, PermissionsMixin):
USER_TYPES = (
('0', 'SuperAdmin'),
('1', 'User'),
('2', 'Manager')
)
GENDER_TYPES = (
('0', 'Male'),
('1', 'FeMale'),
('2', 'Others')
)
first_name = models.CharField(('first_name'), max_length=50)
last_name = models.CharField(('last_name'), max_length=50)
username = models.CharField(('username'), max_length=150, unique=True)
country_code = models.CharField(('country_code'), max_length=6)
mobile_number = models.CharField(('phone number'), max_length=10, unique=True)
email = models.EmailField(('email address'), max_length=200, unique=True)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
gender = models.CharField(max_length=1, choices=GENDER_TYPES, default=0)
image = models.ImageField(upload_to='images', null=True)
address = models.CharField(('user address'), max_length=200, null=True)
role = models.CharField(max_length=1, choices=USER_TYPES, default='1')
created_at = models.DateTimeField(('created_at'), auto_now_add=True)
updated_at = models.DateTimeField(('updated_at'), auto_now=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=True)
is_superuser = models.BooleanField(default=False)
is_user = models.BooleanField(default=False)
is_manager = models.BooleanField(default=False)
objects = UserManager()
class Meta:
db_table = 'users'
ordering = ['first_name']
def save(self, *args, **kwargs):
if self.is_superuser:
self.role = 0
elif self.is_user:
self.role = 1
self.is_superuser = 0
elif self.is_manager:
self.role = 2
self.is_superuser = 0
super(MyUser, self).save(*args, **kwargs)
forms.py
from django.contrib.auth.forms import UserCreationForm
from material import Layout, Row
from django import forms
from .models import *
class RegistrationForm(forms.Form):
class Meta:
model = MyUser
first_name = forms.CharField(label='First Name', required=True)
last_name = forms.CharField(label='Last Name')
username = forms.CharField(label= 'User Name')
country_code = forms.CharField(label='Country Code')
mobile_number = forms.CharField(label='Mobile Number', required=True,)
email = forms.EmailField(label='Email Address', required=True)
gender = forms.ChoiceField(choices=((None, ''), ('M', 'Male'), ('F', 'FeMale'), ('O', 'Others')))
password = forms.CharField(widget=forms.PasswordInput)
password_confirm = forms.CharField(widget=forms.PasswordInput, label="Confirm Password")
layout = Layout(Row('first_name', 'last_name', 'user_name'),
Row('country_code', 'mobile_number', 'email'),
Row('gender', 'password', 'password_confirm')
)
views.py
from django.shortcuts import render
from .models import MyUser
from .forms import RegistrationForm
from django.views.generic import CreateView
# Create your views here.
class RegistrationView(CreateView):
model = MyUser
form_class = RegistrationForm
template_name = "signup.html"
urls.py
from django.conf.urls import url
from django.urls import path
from . import views
"""
URLS for USERS
"""
urlpatterns=[
url(r'^signup/$', views.RegistrationView.as_view(), name='signup')
]
singup.html
<form method="POST">
{% csrf_token %}
{% form %}
{% part form.username prefix %}<i class="material-icons prefix">account_box</i>{% endpart %}
{% part form.email prefix %}<i class="material-icons prefix">email</i>{% endpart %}
{% part form.password prefix %}<i class="material-icons prefix">lock_open</i>{% endpart %}
{% endform %}
<button type="submit" class="btn">Submit</button>
</form>
please help me how to resolve that error and I have included templates in settings also
PFA of error what I am getting.
Thanks and Regards,
Premkumar Ch.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAG%3DmdoCixWPdQ3C_FmayPDzw1KEbL29Jzkcb-EKGB78H4jEJ4A%40mail.gmail.com.
No comments:
Post a Comment