Extending the User to add a profile_pic

160 views Asked by At

In older versions of Django you could extends the User model and create a UserProfile. It seems now in Django 1.8 this is not nearly the same anymore. Im looking for good examples to do this in Django 1.8.

Here is an example I found somewhere on the net, but it does not extend anything. I want to just extend the user so I can still use the user object in my tempaltes etc.

class MyUser(AbstractBaseUser):
    """
    Custom user class.
    """

    GENDER_CHOICES = (
        ('M', 'Male'),
        ('F', 'Female'),
    )
    email = models.EmailField('email address', unique=True, db_index=True)
    is_staff = models.BooleanField('is staff', default=False)
    first_name = models.TextField('first name', default=None, null=True)
    last_name = models.TextField('last name', default=None, null=True)
    date_of_birth = models.DateField('date of birth', null=True)
    avatar = models.ImageField('profile picture', upload_to='static/media/images/avatars/', null=True, blank=True)
    has_picture = models.BooleanField('has profile picture', default=False)
    adult = models.BooleanField('is adult', default=False)
    gender = models.CharField('gender', max_length=1, choices=GENDER_CHOICES)

    objects = MyUserManager()

    REQUIRED_FIELDS = ['date_of_birth', 'gender']

    USERNAME_FIELD = 'email'

    # Insert a lot of methods here

    def set_avatar(self):
       self.has_picture = True

Useing the followin decoumentation: https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#extending-django-s-default-user

Gives me all these errors:

  Rendering model states...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/hermanstander/apps/afriapps/stem/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/hermanstander/apps/afriapps/stem/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/hermanstander/apps/afriapps/stem/env/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/hermanstander/apps/afriapps/stem/env/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/Users/hermanstander/apps/afriapps/stem/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 221, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/Users/hermanstander/apps/afriapps/stem/env/lib/python2.7/site-packages/django/db/migrations/executor.py", line 100, in migrate
    state.apps  # Render all real_apps -- performance critical
  File "/Users/hermanstander/apps/afriapps/stem/env/lib/python2.7/site-packages/django/utils/functional.py", line 60, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/hermanstander/apps/afriapps/stem/env/lib/python2.7/site-packages/django/db/migrations/state.py", line 166, in apps
    return StateApps(self.real_apps, self.models)
  File "/Users/hermanstander/apps/afriapps/stem/env/lib/python2.7/site-packages/django/db/migrations/state.py", line 248, in __init__
    raise ValueError(msg.format(field=operations[0][1], model=lookup_model))
ValueError: Lookup failed for model referenced by field admin.LogEntry.user: app.UserProfile
0

There are 0 answers