django-users

Django - Multiple User Profiles

戏子无情 提交于 2019-12-02 15:44:38
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 = models.CharField(max_length=32) def __unicode__(self): return self.user.email Which works nicely along with AUTH_PROFILE_MODULE = 'accounts.UserProfile' set in settings.py . However, I have two different kinds of users in my website, Individuals and Corporate, each having their own unique attributes. For instance, I would want my Individual users to have a single user

Setting up two different types of Users in Django 1.5/1.6

久未见 提交于 2019-12-02 14:58:28
Please note--this is an updated version of my original question on this subject, but deserves to be asked again with the change in how Django deals with users and authentication. I'm working on a website with two very different kinds of users--let's call them Customers and Store Owners . Both register on the site, but have very different functionality. Customers simply have a single profile and can shop among the stores that they like. Store Owners have a single account but can have access to multiple stores, and each store can have multiple Store Owners . The exact details of the models don't

Django 1.5 custom user model - signals limitation

末鹿安然 提交于 2019-12-02 09:27:44
It's written in the doc that: Another limitation of custom User models is that you can’t use django.contrib.auth.get_user_model() as the sender or target of a signal handler. Instead, you must register the handler with the resulting User model. See Signals for more information on registering an sending signals. I guess it means you can do the following: from django.contrib.auth import get_user_model User = get_user_model() @receiver(post_save, sender=User) def user_saved(sender=None, instance=None, **kwargs): # something Isn't it? I'm just wondering if I understand well (I don't understand why

django 'User' object has no attribute 'get' error

蓝咒 提交于 2019-12-02 02:34:55
问题 I am writing an simple django application and got stuck into this error, can some one please help me my views.py looks exactly as def custom_login(request): if request.user.is_authenticated(): return HttpResponseRedirect('dashboards') return login(request, 'login.html', authentication_form=LoginForm) def custom_logout(request): return logout(request, next_page='/') def user(request): context = {'user': user, 'groups': request.user.groups.all(), 'dashboards': Dashboard} return render_to

django 'User' object has no attribute 'get' error

此生再无相见时 提交于 2019-12-02 01:24:03
I am writing an simple django application and got stuck into this error, can some one please help me my views.py looks exactly as def custom_login(request): if request.user.is_authenticated(): return HttpResponseRedirect('dashboards') return login(request, 'login.html', authentication_form=LoginForm) def custom_logout(request): return logout(request, next_page='/') def user(request): context = {'user': user, 'groups': request.user.groups.all(), 'dashboards': Dashboard} return render_to_response('registration/dashboards.html', context, context_instance=RequestContext(request)) and my forms.py

django access logged in user in custom manager

拟墨画扇 提交于 2019-12-01 10:43:41
I want to access the currently logged in user in a custom manager I have wrote. I want to do this so that I can filter down results to only show objects they have access to. Is there anyway of doing this without actually passing it in? Something similar to how it works in views where you can do request.user. Thanks Jack M. Without passing it in, the best way I've seen is to use a middleware (described in this StackOverflow question , I'll copy/paste for ease of reference): Middleware: try: from threading import local except ImportError: from django.utils._threading_local import local _thread

Multiple USERNAME_FIELD in django user model

丶灬走出姿态 提交于 2019-12-01 03:56:43
My custom user model: class MyUser(AbstractBaseUser): username = models.CharField(unique=True,max_length=30) email = models.EmailField(unique=True,max_length=75) is_staff = models.IntegerField(default=False) is_active = models.IntegerField(default=False) date_joined = models.DateTimeField(default=None) # Use default usermanager objects = UserManager() USERNAME_FIELD = 'email' Is there a way to specify multiple USERNAME_FIELD ? Something like ['email','username'] so that users can login via email as well as username ? Alasdair The USERNAME_FIELD setting does not support a list. You could create

Turn off user social registration in django-allauth?

半城伤御伤魂 提交于 2019-11-30 21:06:34
I noticed looking through the django-allauth templates there's a signup_closed.html users can be redirected to when user registration is closed or disabled. Does anyone who's familiar with that module know if there's a pre-configured setting that can be set in settings.py to turn off new user registration via existing social apps? Or do I need to configure that myself? I've read the full docs for allauth and I don't see any mention of it. Thanks. Looks like you need to override is_open_for_signup on your adapter. See the code . More information at http://django-allauth.readthedocs.io/en/latest

User manager methods create() and create_user()

為{幸葍}努か 提交于 2019-11-30 20:40:54
I have encountered with some suspicious behavior of create() method of User object manager. Looks like password field isn't required for creating User object if you use this method. In result you get User with blank password . In case when you use create_user method and don't specify password it creates User with unusable password (through to set_unusable_password() ). I am not sure why create() method doesn't raise exception when you try to create user without password - in documentation it's specified that this field is required. Is something wrong in create() method/documentation? That's

Issue with createsuperuser when implementing custom user model

天大地大妈咪最大 提交于 2019-11-30 19:22:05
I am trying to implement my own custom user model in Django 1.6 but I am getting this error. Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/gabriel/.virtualenvs/hang_server/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/Users/gabriel/.virtualenvs/hang_server/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/gabriel/.virtualenvs/hang