Questions tagged [django-users]

User model is the default model in Django. It provides many APIs which are helpful for working with users. Django user model is overridable in a Project according to required field.

Django(a high-level Python Web framework) comes with a user authentication system. It handles user accounts, groups, permissions and cookie-based user sessions.

894 questions
541
votes
17 answers

What's the best way to extend the User model in Django?

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…
Farinha
  • 17,636
  • 21
  • 64
  • 80
94
votes
5 answers

AbstractUser vs AbstractBaseUser in Django?

The use of AbstractUser and AbstractBaseUser looks quite similar. from django.contrib.auth.models import AbstractUser, AbstractBaseUser What is the difference between the two?
Pranjal Mittal
  • 10,772
  • 18
  • 74
  • 99
73
votes
7 answers

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

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…
Himerzi
  • 899
  • 1
  • 8
  • 16
54
votes
3 answers

Django: Hide button in template, if user is not super-user

How do you get your template/view to recognize whether or not a logged in user is a super user or not? There are certain buttons on my forms (in the template) that I want completely hidden if the user is not a super-user How would you go about…
52
votes
4 answers

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

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
Natim
  • 17,274
  • 23
  • 92
  • 150
51
votes
2 answers

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

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 =…
supermario
  • 2,625
  • 4
  • 38
  • 58
36
votes
1 answer

get current user in Django Form

Possible Duplicate: get request data in Django form There's part of my Guest Model: class Guest(models.Model): event = models.ForeignKey(Event, related_name='guests') user = models.ForeignKey(User, unique=True, related_name='guests') …
Yulia
  • 1,575
  • 4
  • 18
  • 27
32
votes
2 answers

What is "swappable" in model meta for?

Looking tough django auth models code, I came across this bit of code: class User(AbstractUser): class Meta(AbstractUser.Meta): swappable = 'AUTH_USER_MODEL' It's obvious that it has something to do with the new AUTH_USER_MODEL setting…
frnhr
  • 12,354
  • 9
  • 63
  • 90
31
votes
1 answer

How to create a new user with django rest framework and custom user model

I have a custom user model and I am using django-rest-framework to create API models.py: class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField( unique=True, max_length=254, ) first_name =…
Aamu
  • 3,431
  • 7
  • 39
  • 61
30
votes
3 answers

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

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 =…
Tony Guinta
  • 633
  • 1
  • 8
  • 14
30
votes
4 answers

Django User model, adding function

I want to add a new function to the default User model of Django for retrieveing a related list of Model type. Such Foo model: class Foo(models.Model): owner = models.ForeignKey(User, related_name="owner") likes = models.ForeignKey(User,…
Hellnar
  • 62,315
  • 79
  • 204
  • 279
30
votes
2 answers

Django Abstract User Error

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…
byrdr
  • 5,197
  • 12
  • 48
  • 78
29
votes
3 answers

Add image/avatar field to users

I want that each user on my website will have an image in his profile. I don't need any thumbnails or something like that, just a picture for each user. The simpler the better. The problem is I don't know how to insert this type of field into my…
hagutm
  • 626
  • 1
  • 7
  • 11
29
votes
3 answers

custom django-user object has no attribute 'has_module_perms'

My custom user model for login via email: class MyUser(AbstractBaseUser): id = models.AutoField(primary_key=True) # AutoField? is_superuser = models.IntegerField(default=False) username = models.CharField(unique=True,max_length=30) …
Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
27
votes
3 answers

Django - Multiple User Profiles

Initially, I started my UserProfile like this: from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model): user = models.OneToOneField(User) verified = models.BooleanField() mobile =…
Aziz Alfoudari
  • 5,193
  • 7
  • 37
  • 53
1
2 3
59 60