Need to Add One Or More Fields in Signup

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Need to Add One Or More Fields in Signup

Pravin Yadav
Hello,

I want to add the one or more fields in User Models/Table.
Kindly let me know about this module.

My code below:-

def register(request):

if request.method == 'POST':
first_name = request.POST['first_name']
last_name = request.POST['last_name']
email = request.POST['email']
password = request.POST['password']
username= str(first_name).lower() + str(last_name).lower()
userdatalist = User.objects.filter(email=email).count() or User.objects.filter(username=username).count()
if userdatalist == 0:
new_user = User.objects.create_user(
username= email,
first_name=first_name,
last_name=last_name,
email=email,
password=password,
is_active=0,
age=age
)
hostname = request.get_host
context = {'first_name': first_name, 'last_name': last_name, 'pk': new_user.id, 'hostname': hostname}
to_email = email
from_email = 'VideoWithFriends'
html_message = render_to_string('mails/useractivation.html', context)
subject = 'Your account has been created successfully.'
email = EmailMultiAlternatives(subject, html_message, from_email, [to_email])
email.attach_alternative(html_message, "text/html")
if(email.send()):
success = 1
return HttpResponse(success);
else:
success = 2
return HttpResponse(success);
else:
error = 0
return HttpResponse(error);

I haven't created any model of User. I have called the predefined models of User.
When i'm adding extra fields like (age). it's showing errors.
kindly let me how  it will be fixed.


Thanks,
Pravin Yadav

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/05199455-aad3-4390-ac93-d902f2361680%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Need to Add One Or More Fields in Signup

Dan Nepejchal
Hi,
I think you must define your own user model, with inherit from django user model...
class User(AbstractUser): bio = models.TextField(max_length=500, blank=True) location = models.CharField(max_length=30, blank=True) birth_date = models.DateField(null=True, blank=True)

and settings:
AUTH_USER_MODEL = 'core.User'


po 11. 6. 2018 v 16:37 odesílatel Pravin Yadav <[hidden email]> napsal:
Hello,

I want to add the one or more fields in User Models/Table.
Kindly let me know about this module.

My code below:-

def register(request):

if request.method == 'POST':
first_name = request.POST['first_name']
last_name = request.POST['last_name']
email = request.POST['email']
password = request.POST['password']
username= str(first_name).lower() + str(last_name).lower()
userdatalist = User.objects.filter(email=email).count() or User.objects.filter(username=username).count()
if userdatalist == 0:
new_user = User.objects.create_user(
username= email,
first_name=first_name,
last_name=last_name,
email=email,
password=password,
is_active=0,
age=age
)
hostname = request.get_host
context = {'first_name': first_name, 'last_name': last_name, 'pk': new_user.id, 'hostname': hostname}
to_email = email
from_email = 'VideoWithFriends'
html_message = render_to_string('mails/useractivation.html', context)
subject = 'Your account has been created successfully.'
email = EmailMultiAlternatives(subject, html_message, from_email, [to_email])
email.attach_alternative(html_message, "text/html")
if(email.send()):
success = 1
return HttpResponse(success);
else:
success = 2
return HttpResponse(success);
else:
error = 0
return HttpResponse(error);

I haven't created any model of User. I have called the predefined models of User.
When i'm adding extra fields like (age). it's showing errors.
kindly let me how  it will be fixed.


Thanks,
Pravin Yadav

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/05199455-aad3-4390-ac93-d902f2361680%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADS85tyidM_fBZPw9CjDxYp3i%3DjoAZRLko5GB5h3%2BN-K52D8Mw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.