django-users

How do I inline edit a django user profile in the admin interface?

亡梦爱人 提交于 2019-11-28 16:44:36
If you want to store extra information about a user (django.contrib.auth.models.User) in Django you can use the nifty AUTH_PROFILE_MODULE to plug in a "profile" model. Each user then gets a profile. It's all described here: http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users http://www.djangobook.com/en/1.0/chapter12/#cn222 Now, let's say I have created an application called accounts with a model called UserProfile and registered it as the profile model for my users. How do I inline the editing of the profile in the admin interface for editing users (or

request.user returns a SimpleLazyObject, how do I “wake” it?

不羁的心 提交于 2019-11-28 06:41:22
I have the following method: def _attempt(actor): if actor.__class__ != User: raise TypeError Which is called from a view: self.object.attempt(self.request.user) As you can see, the _attempt method expects actor to be type django.contrib.auth.models.User , however the object appears to be of type django.utils.functional.SimpleLazyObject . Why is this so? And more importantly, how can I convert the LazyObject (which apparently is a kind of wrapper for a User object) into a User object? More info on Request.user is available here: https://docs.djangoproject.com/en/dev/ref/request-response/

How to extend UserCreationForm with fields from UserProfile

走远了吗. 提交于 2019-11-28 06:12:13
问题 I found this post on how to extend the UserCreationForm with extra fields such as "email." However, the email field is already defined in the pre-built user model. I created an extra model (called UserProfile) that futher extends Django's pre-built User class. How do I get these fields I defined in UserProfile to appear in my UserCreationForm? 回答1: Add fields as appropriate for your UserProfile model (it's not too easy to use a ModelForm to avoid Repeating Yourself, unfortunately), then

How to implement password change form in Django 1.9

£可爱£侵袭症+ 提交于 2019-11-28 05:53:44
问题 The url for my python project is here: https://github.com/abylikhsanov/social I am trying to implement the password change form, so the user can change his or her password. How can I implement it? The application should keep track of the previous password and should not allow the user to use a previously used password. Also, I want to implement the reset password function. 回答1: why don't you use django's built-in PasswordChangeForm (django.contrib.auth.forms). If you like the way it works

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

How to customize the auth.User Admin page in Django CRUD?

血红的双手。 提交于 2019-11-28 03:48:32
I just want to add the subscription date in the User list in the Django CRUD Administration site. How can I do that ? Thank you for your help I finally did like this in my admin.py file : from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User UserAdmin.list_display = ('email', 'first_name', 'last_name', 'is_active', 'date_joined', 'is_staff') admin.site.unregister(User) admin.site.register(User, UserAdmin) Another way to do this is extending the UserAdmin class. You can also create a function to put on list_display from django.contrib.auth.admin import

In Django, how do you pass a ForeignKey into an instance of a Model?

眉间皱痕 提交于 2019-11-27 23:13:46
I am writing an application which stores "Jobs". They are defined as having a ForeignKey linked to a "User". I don't understand how to pass the ForeignKey into the model when creating it. My Model for Job worked fine without a ForeignKey, but now that I am trying to add users to the system I can't get the form to validate. models.py: from django.db import models from django import forms from django.contrib.auth.models import User class Job(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=50, blank=True) pub_date = models.DateTimeField('date published', auto_now

Django: Why create a OneToOne to UserProfile instead of subclassing auth.User?

删除回忆录丶 提交于 2019-11-27 20:50:20
Note: If you are tempted to 'answer' this question by telling me that you don't like django.contrib.auth, please move on. That will not be helpful. I am well aware of the range and strength of opinions on this matter. Now, the question: The convention is to create a model, UserProfile, with a OneToOne to User. In every way I can think of, a more efficient and effective approach is to subclass User to a class that one intends to use for every human in the system - a class called, say, Person(User). I have not seen a coherent explanation of why the former is conventional and the latter is

Django Abstract User Error

若如初见. 提交于 2019-11-27 12:50:59
问题 I am working on extending the User class based on the docs with the code below: from django.contrib.auth.models import AbstractUser class MyUser(AbstractUser): some_extra_data = models.CharField(max_length=100, blank=True) However, I'm returning the following error Reverse accessor for 'User.groups' clashes with reverse accessor for 'MyUser.groups'. HINT: Add or change a related_name argument to the definition for 'User.groups' or 'MyUser.groups'. I understand resolving this type of conflict

Add image/avatar field to users in django

早过忘川 提交于 2019-11-27 10:34:43
I want that each user in my website will have an image in his profile. I don't need any thumbnails or something like that, just picture for each user. The simpler the better. The problem is I don't know how to insert this type of field to my user profile. Any suggestions? Brandon You need to make a form that has a clean method that validates the properties you're looking for: #models.py from django.contrib.auth.models import User class UserProfile(models.Model): user = models.OneToOneField(User) avatar = models.ImageField() #forms.py from django import forms from django.core.files.images