0

I have created a custom User SignUp Class.

class SignUp(models.Model):
    userId = models.CharField(max_length=8, blank=False, unique=True)
    Name = models.CharField(max_length=200)
    VehicleNumber= models.CharField(max_length=12)
    ContactNum = models.IntegerField(default=0)
    def __unicode__(self):
        return smart_unicode(self.Name)

I have used this to create a Sign up form. Now, I am not getting a way for creating user login. Note: I can't use django in-built users because they don't have a field for images.

kartikmaji
  • 946
  • 7
  • 22
  • you can use django in-built user, just need to extend it with your new attributes. – levi Aug 20 '14 at 18:11
  • I tried that but since I am a newbee, I was not able to help myself. Can you guide me specifically how to do this. – kartikmaji Aug 20 '14 at 18:14

2 Answers2

0

You can use and extend the built-in model User. The shortest path is

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

class UserWithPhoto(User):
    image = models.ImageField()

but is better practice to use User Profiles, you can read about it in: User authentication in Django

You can read about this in Django user profile and here Extending the User model with custom fields in Django.

Why is better user profile over extending the User model directly?

If you extend the User model you will have the changes applied to all you users. Think about this, you could have Administrators, Developers, Reviwers, even Guests, all of them might have some field that others don't, so a different profile for each one is the better solution than subclassing User for each one, or even worst create a single class with all fields you need for all kinds of users (only think about it hurts ).

Community
  • 1
  • 1
Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60
0

You can extend the built-in django user, by adding OneToOneField.

YourCustomUser(models.Model):
    user = models.OneToOneField(User,related_name='profile')
    image = models.ImageField()
    //put here your others attributes

If you have YourCustomUser instance and want to access to User built-in instance

your_custom_instance.user

If you have User built-in instance and want to retrieve e.i the image

user.profile.image
levi
  • 22,001
  • 7
  • 73
  • 74