django-profiles

django profies and request.user - error

拈花ヽ惹草 提交于 2020-01-05 05:56:10
问题 I'm getting the following error: 'AnonymousUser' object has no attribute 'get_profile' after I added the following middleware, and try to log on to my site without having logged on before: class TimezoneMiddleware(object): def process_request(self, request): try: driver = request.user.get_profile() timezone.activate(driver.timezone) except ObjectDoesNotExist: timezone.activate('UTC') In the traceback, the error occurs at the first line of the try statement. Thanks in advance for the help! 回答1

Django: When extending User, better to use OneToOneField(User) or ForeignKey(User, unique=True)?

廉价感情. 提交于 2019-12-28 08:11:43
问题 I'm finding conflicting information on whether to use OneToOneField(User) or ForeignKey(User, unique=True) when creating a UserProfile model by extending the Django User model. Is it better to use this?: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) or this?: class UserProfile(models.Model): user = models.OneToOneField(User) The Django Doc specifies OneToOneField , while the Django Book example uses ForeignKey . James Bennett also has two Blog posts that

django-registration creating blank django-profiles using signals

試著忘記壹切 提交于 2019-12-13 07:36:12
问题 I have gone through the solution here and Shacker's django-profiles: The Missing Manual and subsequent signals solution by Dmitko and answers here and many places. Here are the details: AUTH_PROFILE_MODULE = "members.Profile " From members.models.py class Profile(models.Model): """member model.""" GENDER_CHOICES = ( (1, 'Male'), (2, 'Female'), ) user = models.ForeignKey(User, unique=True) first_name = models.CharField(_('first name'), max_length=100) middle_name = models.CharField(_('middle

django profile creation, set User profile while using multiple profile types

一个人想着一个人 提交于 2019-12-11 06:52:26
问题 I am stuck at user registration, I actually intends to have different profile types. While registration I am unable to set UserProfile while creating a user. I am using UserCreationForm. code in my files are as following. from django.contrib.auth.forms import UserCreationForm from registration.forms import RegistrationForm from django import forms from django.contrib.auth.models import User from accounts.models import UserProfile from django.utils.translation import ugettext_lazy as _ from

Django custom user model: How to manage staff permissions?

我怕爱的太早我们不能终老 提交于 2019-12-11 06:49:35
问题 I'm trying to benefit from Django 1.5 and created custom user model. In order to use builtin permissions, which I would like to limit access with in the admin interface. I inherited my user class also from PermissionMixin. But when I create new user and check Staff box, the new user gets all the access that superuser has. What am I doing wrong? models.py class MyUserManager(BaseUserManager): def create_user(self, email, password=None): if not email: raise ValueError(_('Users must have an

What's the best way to have different profiles for different kinds of users in django?

喜夏-厌秋 提交于 2019-12-03 13:34:24
问题 In my application I have students, professors and staff. Staff members do not need a profile but professors and students each need a different profile. I'd rather not implement it all myself (middleware and whatnot), so is there anyway to just have get_profile() return a different profile depending on a user's role? 回答1: With Django 1.1, which is currently in beta, I would implement a proxy model. class MyUser(User): class Meta: proxy = True def get_profile(self): if self.role == 'professor':

What's the best way to have different profiles for different kinds of users in django?

北战南征 提交于 2019-12-03 03:31:21
In my application I have students, professors and staff. Staff members do not need a profile but professors and students each need a different profile. I'd rather not implement it all myself (middleware and whatnot), so is there anyway to just have get_profile() return a different profile depending on a user's role? With Django 1.1, which is currently in beta, I would implement a proxy model . class MyUser(User): class Meta: proxy = True def get_profile(self): if self.role == 'professor': return ProfessorProfile._default_manager.get(user_id__exakt=self.id) elif self.role == 'student': return

Django: When extending User, better to use OneToOneField(User) or ForeignKey(User, unique=True)?

耗尽温柔 提交于 2019-11-28 04:09:09
I'm finding conflicting information on whether to use OneToOneField(User) or ForeignKey(User, unique=True) when creating a UserProfile model by extending the Django User model. Is it better to use this?: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) or this?: class UserProfile(models.Model): user = models.OneToOneField(User) The Django Doc specifies OneToOneField , while the Django Book example uses ForeignKey . James Bennett also has two Blog posts that providing conflicting examples as well: Extending the User Model User Registration In the former post, Bennett