3

I use django 1.5 with custom model MyUser. I want to make users profile page, where he can modify only one field - 'about'. I tried something like that:

forms.py:

class UserSettingsForm(forms.ModelForm):
class Meta:
    model = get_user_model()
    fields = ('about')

view.py:

class UserSettings(UpdateView):
form_class = UserSettingsForm
template_name = "user/settings.html"
def get_object(self, queryset=None):
    return self.request.user
def get_success_url(self):
    return reverse('user_detail', args=[self.request.user.username])

urls:

url(r'^settings/$', UserSettings.as_view(), name='user_settings')

model:

    class MyUserManager(BaseUserManager):
def create_user(self, email, password=None):
    """
    Creates and saves a User with the given email, date of
    birth and password.
    """
    if not email:
        raise ValueError('Users must have an email address')

    user = self.model(
        email=MyUserManager.normalize_email(email),
       # date_of_birth=date_of_birth,
    )

    user.set_password(password)
    user.save(using=self._db)
    return user

def create_superuser(self, email, password):
    """
    Creates and saves a superuser with the given email, date of
    birth and password.
    """
    user = self.create_user(email,
        password=password,
        #date_of_birth=date_of_birth
    )
    user.is_admin = True
    user.save(using=self._db)
    return user


class MyUser(AbstractBaseUser):
email = models.EmailField(
    verbose_name='email address',
    max_length=255,
    unique=True,
    db_index=True,
)
last_name=models.CharField(max_length=30)
first_name=models.CharField(max_length=30)
about=models.TextField(blank=True)

objects = MyUserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['last_name','first_name','about']

def get_full_name(self):
    # The user is identified by their email address
    return self.email

def get_short_name(self):
    # The user is identified by their email address
    return self.email

def __unicode__(self):
    return self.email

def has_perm(self, perm, obj=None):
    "Does the user have a specific permission?"
    # Simplest possible answer: Yes, always
    return True

def has_module_perms(self, app_label):
    "Does the user have permissions to view the app `app_label`?"
    # Simplest possible answer: Yes, always
    return True

@property
def is_staff(self):
    "Is the user a member of staff?"
    # Simplest possible answer: All admins are staff
    return self.is_admin

But I got error: django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'app.MyUser' that has not been installed

How can I make users profile in django 1.5? Thx!

Wolter
  • 1,053
  • 3
  • 11
  • 17

1 Answers1

0

MyUser class should be under the application named 'app' in your settings file in order for the auth framework to pick it.

almalki
  • 4,595
  • 26
  • 30
  • what do you mean "class under application"? My settings.py: INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_admin_bootstrapped', 'django.contrib.admin','app', ) AUTH_USER_MODEL = 'app.MyUser' – Wolter Feb 25 '13 at 13:28
  • @Wolter I mean class MyUser should be in models.py of "app" – almalki Feb 25 '13 at 14:12
  • I have only one model.py in my project. – Wolter Feb 25 '13 at 14:28
  • @Wolter I suspect get_user_model() of UserSettingsForm is causing the problem, try with MyUser instead. – almalki Feb 25 '13 at 14:48