django-users

How to use 'User' as foreign key in Django 1.5

≡放荡痞女 提交于 2019-11-27 10:15:22
问题 I have made a custom profile model which looks like this: from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model): user = models.ForeignKey('User', unique=True) name = models.CharField(max_length=30) occupation = models.CharField(max_length=50) city = models.CharField(max_length=30) province = models.CharField(max_length=50) sex = models.CharField(max_length=1) But when I run manage.py syncdb , I get: myapp.userprofile: 'user' has a relation

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

流过昼夜 提交于 2019-11-27 01:32:02
问题 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

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

爱⌒轻易说出口 提交于 2019-11-27 00:12:21
问题 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 回答1: 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) 回答2: Another way to do this is extending the

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

时光怂恿深爱的人放手 提交于 2019-11-26 23:16:57
问题 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 =

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

。_饼干妹妹 提交于 2019-11-26 20:28:13
问题 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

Extending the User model with custom fields in Django

ぐ巨炮叔叔 提交于 2019-11-26 01:19:06
问题 What\'s the best way to extend the User model (bundled with Django\'s authentication app) with custom fields? I would also possibly like to use the email as the username (for authentication purposes). I\'ve already seen a few ways to do it, but can\'t decide on which one is the best. 回答1: The least painful and indeed Django-recommended way of doing this is through a OneToOneField(User) property. Extending the existing User model … If you wish to store information related to User , you can use