Need to Add One Or More Fields in Signup

7 views
Skip to first unread message

Pravin Yadav

unread,
Jun 11, 2018, 10:37:03 AM6/11/18
to Django users
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

Dan Nepejchal

unread,
Jun 11, 2018, 10:52:03 AM6/11/18
to django...@googlegroups.com
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 <pk.j...@gmail.com> napsal:
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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 all
Reply to author
Forward
0 new messages