django-users

Django User Update Form and View

谁说胖子不能爱 提交于 2020-01-03 01:37:13
问题 I am very early on in my Django/Python development journey, most things I have been able to slowly figure out after a few hours/days of head scratching and trial/error. I now have the commonly asked question that I cannot get working correctly: How Do I Create a User Profile Update View/Form? I have hacked on several solutions from Stack Overflow, and just cannot figure out what I am doing wrong thus far. Here is the initial version of my poor attempt using Django 1.9: #forms.py class

django 1.5 extend the default User model or substitute it

泪湿孤枕 提交于 2019-12-30 10:24:07
问题 Env: Django 1.5.1 + Django CMS 2.4.1 + Zinnia latest + my custom apps + custom Django CMS plugin Basically I can extend the default Django (1.5.X) User model like Django Ribbit Tutorial on NetTuts+ or Substitute a completely customized model like Django Dev doc or Django2Scoops example in the paragraph: "Dealing With the User Model" To test I decided for Subclass AbstractUser From Django2Scoops book:"Choose this option if you like Django’s User model fields the way they are, but need extra .

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

how to attach multiple ModelAdmins to UserAdmin in Django?

家住魔仙堡 提交于 2019-12-25 04:25:08
问题 I have a search model which has a ForeignKey relation to User class Searches(models.Model): user = models.ForeignKey(User) ...... I have a UserProfile model which has a OnetoOne Relationship to User class UserProfile(models.Model): user = models.OneToOneField(User) photo = models.ImageField(upload_to='profile_images', blank=True) ispublic=models.NullBooleanField() I have attached UserProfile in admin.py as follows: class UserProfileInline(admin.StackedInline): model = UserProfile can_delete =

django.core.exceptions.FieldError: Unknown field(s) specified by user

你说的曾经没有我的故事 提交于 2019-12-24 17:16:05
问题 I'm using Django 2.0 I have extended AbstractBaseUser model to create a custom User model. In my accounts/models.py class UserManager(BaseUserManager): def create_user(self, email, password=None, is_staff=False, is_admin=False, is_active=False): if not email: raise ValueError('User must have an email address') if not password: raise ValueError('User must have a password') user = self.model( email=self.normalize_email(email) ) user.is_staff = is_staff user.is_admin = is_admin user.is_active =

Work with two Users table

痞子三分冷 提交于 2019-12-24 16:39:52
问题 I wonder if is it possible to use the default django.contrib.auth.models.User to store admins users, users created with python manage.py createsuperuser , but use another table to store registered by form users, also users that will be registered with Social provides ( python-social-auth ). By using another table for users I will need to use the same password hashing also. Use a 1-to-1 relationship with auth_users is not an option. Thanks. 回答1: Well, this is how I did this: From python-social

AUTH_USER_MODEL does not accept sub application

送分小仙女□ 提交于 2019-12-24 03:15:44
问题 I am having problems with my custom user model while using Django 1.7.1 and Python 3.4 . I have declared a Custom user model in an apps.users.AuthUser. I then have another application (apps.pets) that will use the AuthUser as a ForeignKey in a Pet model. See below: class Pet(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL, db_index=True, blank=False, null=False) This is my scenario: In my INSTALLED_APPS I have: "apps.users" If I set AUTH_USER_MODEL="apps.users.AuthUser" the

How can I implement custom user manager in django?

大憨熊 提交于 2019-12-23 15:49:07
问题 I create custom User models inheriting AbstractUser in Django : class ChachaUser(AbstractUser): birth = models.DateField() gender = models.CharField(max_length=1, choices=GENDER_CHOICES) and my CustomUserCreationForm : GENDER_CHOICES = ( ('M', '남'), ('F', '여'), ) class MyUserCreationForm(UserCreationForm): birth = forms.DateField( widget=forms.SelectDateWidget( years=range(1970, 2015) ), required=True, ) gender = forms.ChoiceField(choices=GENDER_CHOICES, initial='M') class Meta

Get current user log in signal in Django

前提是你 提交于 2019-12-20 19:16:20
问题 I am just using the admin site in Django. I have 2 Django signals (pre_save and post_save). I would like to have the username of the current user. How would I do that? It does not seem I can send a request Or I did not understand it. Thanks 回答1: If you are using the admin site why not use a custom model admin class MyModelAdmin( admin.ModelAdmin ): def save_model( self, request, obj, form, change ): #pre save stuff here obj.save() #post save stuff here admin.site.register( MyModel,

Extending User object in Django: User model inheritance or use UserProfile?

筅森魡賤 提交于 2019-12-20 11:54:13
问题 To extend the User object with custom fields, the Django docs recommend using UserProfiles. However, according to this answer to a question about this from a year or so back: extending django.contrib.auth.models.User also works better now -- ever since the refactoring of Django's inheritance code in the models API. And articles such as this lay out how to extend the User model with custom fields, together with the advantages (retrieving properties directly from the user object, rather than