Re: djano user registration form and login(full example)

1,876 views
Skip to first unread message

Shawn Milochik

unread,
Apr 1, 2013, 3:19:52 PM4/1/13
to django...@googlegroups.com
Don't even worry about factories. They're for when you want a bunch of
forms for the same model on the page at once.

Use the UserCreationForm in django.contrib.auth.forms. It only accepts
a username and password, so you can either subclass it to add the
fields or make your own form and add it to your view so that they both
appear in the same HTML form. You can validate both and do what you
need to do.

You definitely shouldn't be writing validation logic for the password
and username and such -- that's what ModelForms are for.

If you have more specific questions just ask.

Alexis Roda

unread,
Apr 1, 2013, 3:24:30 PM4/1/13
to django...@googlegroups.com
Al 01/04/13 21:11, En/na sachin ha escrit:
> Hello,
>
> I'm just starting with Django. I want to create a user registration form
> which will take input like username, password, first and last name,
> email, address etc.
> using the same information I want to send a conformation mail to user
> and authenticate her/him.

Hi sachin,
I'd suggest you to take a look at django-registration. It does what
you're asking for.

https://bitbucket.org/ubernostrum/django-registration
http://docs.b-list.org/django-registration/0.8/


HTH

sachin

unread,
Apr 6, 2013, 9:37:32 AM4/6/13
to django...@googlegroups.com
Thanx Shawn,

UserCreationForm really helped.

Now I have a different problem, I'm trying to add custom feilds to auth user using storing-additional-information-about-users.
But now I m getting this error.

Exception Type:IntegrityError
Exception Value:
column user_id is not unique


This is my models.py file:

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    sr_no = models.CharField(max_length=10)

    def __unicode__(self):
        return self.sr_no

def create_user_profile(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

I have added unique field, but it does not make any difference. So far I haven't got
any convincing answer. 

Any Idea ??

Shawn Milochik

unread,
Apr 6, 2013, 10:30:59 AM4/6/13
to django...@googlegroups.com
I've seen some situations where it looked like signals are received multiple times.

However, you can easily fix that by checking for the existence of the user in your function, or a try/except that handles the integrity error.

Also, if you're starting a new project, consider upgrading to Django 1.5. It's similar to 1.4 
(which I assume you're using based on the documentation link you provided), but also has customizable user models.

Although creating a profile model to be linked to the User model is still a good idea, some fields make sense to have
in a custom User model:

Shawn


Thomas Rega

unread,
Apr 8, 2013, 1:35:56 AM4/8/13
to django...@googlegroups.com
Am 06.04.2013 um 16:30 schrieb Shawn Milochik:

I've seen some situations where it looked like signals are received multiple times.

However, you can easily fix that by checking for the existence of the user in your function, or a try/except that handles the integrity error.


just my two cents …


Also, if you're starting a new project, consider upgrading to Django 1.5. It's similar to 1.4 
(which I assume you're using based on the documentation link you provided), but also has customizable user models.

Although creating a profile model to be linked to the User model is still a good idea, some fields make sense to have
in a custom User model:

Shawn



--
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

sachin

unread,
Apr 17, 2013, 1:15:36 AM4/17/13
to django...@googlegroups.com
I m still stuck with

Exception Type:     IntegrityError
Exception Value:     column user_id is not unique

Whenever I try to save, it throws the above error.

I have attached files for reference, can someone help ??
models.py
forms.py
views.py
admin.py

Avnesh Shakya

unread,
Apr 17, 2013, 1:39:36 AM4/17/13
to django...@googlegroups.com
This error is occur when you're saving the member, not the user. When creating the member, you are not assigning the user.


--

isachin

unread,
Apr 17, 2013, 3:28:46 AM4/17/13
to django...@googlegroups.com
Thanx,

Btw, I solved it by creating an instance of get_profile() and then saving user and profile separately.

here is the code snippet of forms.py

if commit:
        profile = user.get_profile()
        profile.serial_num = self.cleaned_data['serial_num']
        profile.save()
        user.save()
 return user, profile





--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/8PHPgI4i4sQ/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Sachin

sachin

unread,
Apr 18, 2013, 1:03:11 AM4/18/13
to django...@googlegroups.com
Hello again,

In extended auth user model, is there any way to handle unique fields with django forms.

Lets say I have model like:

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    phone_num = models.BigIntegerField(null=True, unique=True)

    def __unicode__(self):
    return "%s" % self.user


so how can a user gets an error message if the phone number already exist?
Is there any django way to handle this??
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/8PHPgI4i4sQ/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Sachin
Reply all
Reply to author
Forward
0 new messages