User Registration

63 views
Skip to first unread message

Arshpreet Singh

unread,
Jun 8, 2016, 6:49:31 AM6/8/16
to django...@googlegroups.com
I am implementing Django User registration method as provided in the
following tutorial:

https://mayukhsaha.wordpress.com/2013/05/09/simple-login-and-user-registration-application-using-django/

It is not using any model/model-form, But I want to connect with
User-registration with other defined model.

Is it possible using the above tutorial or I have to create new
UserRegistration model?

--

Thanks
Arshpreet Singh
Python Developer
RevinfoTech
Web Development/Data Science/Systems Integration
Mobile: (91)987 6458 387
http://www.revinfotech.com/
https://www.linkedin.com/in/arsh840

ludovic coues

unread,
Jun 8, 2016, 7:00:37 AM6/8/16
to django...@googlegroups.com
Have you looked at the django documentation ?
There is a builtin form for creating a new user, working with user
model shipped with django.
https://docs.djangoproject.com/en/1.9/topics/auth/default/#django.contrib.auth.forms.UserCreationForm
> --
> 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/CAAstK2GtNnR9N%3Dg2-m8ZHKt9R4Bt4nUJFjBXpMdGoD%2B73nujRg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

vai...@ebex.com.au

unread,
Jun 9, 2016, 12:24:06 AM6/9/16
to Django users
HI,
You can create a custom model like this and define all custom fields within it:
class UserInfo(AbstractTimestampClass):
    user = models.ForeignKey(User)
    address = models.TextField(blank=True, null=True)
    city = models.CharField(max_length=25, blank=True, null=True)
    postal_code = models.CharField(max_length=20, blank=True, null=True)
    state = models.CharField(max_length=40, blank=True, null=True)
    country = models.CharField(max_length=100, blank=True, null=True)
    company = models.CharField(max_length=100, blank=True, null=True)
    phone = models.CharField(max_length=25, blank=True, null=True)
    fax = models.CharField(max_length=25, blank=True, null=True)

Note the above model is referring to the in built User model through foreign key relationship.
On registration API you would need to create both User and UserInfo objects.
Something like:
user = User.objects.create_user(username=validated_data['email'],
                                        email=validated_data['email'],
                                        password=validated_data['password'],)
UserInfo.objects.create(user=user,
                                address=validated_data['address'],
                                city=validated_data['city'],etc.)
That would suffice.
Reply all
Reply to author
Forward
0 new messages