django-custom-manager

Can't login to django admin after creating a super user with a custom user model

左心房为你撑大大i 提交于 2019-12-18 16:34:12
问题 I've been trying for hours to login to the django admin panel with a successfully created superuser but cannot get the right username/pw combo right. I want users to just use their email as their username. I've also done my best to replicate the example in the Django docs here. I've deleted migrations, sycndb, and everything works except logging in to the admin panel. Relevant code: From models.py : from django.db import models from django.forms import ModelForm from django.contrib.auth

Django custom managers - how do I return only objects created by the logged-in user?

柔情痞子 提交于 2019-12-17 07:05:44
问题 I want to overwrite the custom objects model manager to only return objects a specific user created. Admin users should still return all objects using the objects model manager. Now I have found an approach that could work. They propose to create your own middleware looking like this: #### myproject/middleware/threadlocals.py try: from threading import local except ImportError: # Python 2.3 compatibility from django.utils._threading_local import local _thread_locals = local() def get_current

How to solve error raised : No module named 'django.contrib.customuser'

和自甴很熟 提交于 2019-12-12 09:57:45
问题 I am new to Django, trying to create a custom user for my project. When I am running the server, it raises No module named 'django.contrib.customuser' and sometimes, Manager isn't available; auth.User has been swapped for Mysite.CustomUser. Even i changed my settings: django.contrib.auth to django.contrib.custommuser. Please someone help me solving this. Here's my code models.py: from datetime import datetime from django.db import models from django.contrib.auth.models import User,

Single custom Manager for Multiple models in Django

谁说我不能喝 提交于 2019-12-11 01:19:19
问题 I have several models connected to each other with ForeignKeys relationships. The main one in this sort of hierarchy contains a owner field. I would like to create a single custom manager for all these models that changes the returned queryset depending on the models that is calling it. I know that manager can access self.model to get the model that it is attached to. Class Main(models.Model) owner=models.ForeignKey (User) owned = OwnedManager() Class Second(models.Model) main=models

Django extending objects manager raises 'NoneType' object has no attribute '_meta'

[亡魂溺海] 提交于 2019-12-10 20:55:45
问题 I am trying to create a custom objects manager as described https://docs.djangoproject.com/en/dev/topics/db/managers/#modifying-initial-manager-querysets I am doing something like this: # the model, say Alpha class MyManager(Manager): pass Alpha.objects = MyManager() Which I think should not do anything. But just setting this raises 'NoneType' object has no attribute '_meta' . How is this possible? I think I am following the example rather closely. I checked and Alpha.objects before the

TypeError: create_superuser() missing 1 required positional argument: 'profile_picture'

我是研究僧i 提交于 2019-12-07 13:53:19
问题 I get the following error after adding the profile_picture field: TypeError: create_superuser() missing 1 required positional argument: 'profile_picture' This profile_picture field is an "ImageField" set as "Null = True". I have tried the following: def create_user(...., profile_picture=None, ....) . It didn't work. and the error occurs only in command prompt when i create superuser from there. Here is my models.py from django.db import models from django.contrib.auth.models import

How to solve error raised : No module named 'django.contrib.customuser'

江枫思渺然 提交于 2019-12-06 06:26:22
I am new to Django, trying to create a custom user for my project. When I am running the server, it raises No module named 'django.contrib.customuser' and sometimes, Manager isn't available; auth.User has been swapped for Mysite.CustomUser. Even i changed my settings: django.contrib.auth to django.contrib.custommuser. Please someone help me solving this. Here's my code models.py: from datetime import datetime from django.db import models from django.contrib.auth.models import User, BaseUserManager, AbstractUser, AbstractBaseUser from django.utils.translation import ugettext_lazy as _ class

TypeError: create_superuser() missing 1 required positional argument: 'profile_picture'

戏子无情 提交于 2019-12-06 03:14:44
I get the following error after adding the profile_picture field: TypeError: create_superuser() missing 1 required positional argument: 'profile_picture' This profile_picture field is an "ImageField" set as "Null = True". I have tried the following: def create_user(...., profile_picture=None, ....) . It didn't work. and the error occurs only in command prompt when i create superuser from there. Here is my models.py from django.db import models from django.contrib.auth.models import BaseUserManager, AbstractBaseUser class UserManager(BaseUserManager): def create_user(self, email, full_name,

Can't login to django admin after creating a super user with a custom user model

情到浓时终转凉″ 提交于 2019-11-30 13:59:14
I've been trying for hours to login to the django admin panel with a successfully created superuser but cannot get the right username/pw combo right. I want users to just use their email as their username. I've also done my best to replicate the example in the Django docs here . I've deleted migrations, sycndb, and everything works except logging in to the admin panel. Relevant code: From models.py : from django.db import models from django.forms import ModelForm from django.contrib.auth.models import BaseUserManager, AbstractBaseUser class UserManager(BaseUserManager): def create_user(self,

Django custom managers - how do I return only objects created by the logged-in user?

浪子不回头ぞ 提交于 2019-11-27 03:01:34
I want to overwrite the custom objects model manager to only return objects a specific user created. Admin users should still return all objects using the objects model manager. Now I have found an approach that could work. They propose to create your own middleware looking like this: #### myproject/middleware/threadlocals.py try: from threading import local except ImportError: # Python 2.3 compatibility from django.utils._threading_local import local _thread_locals = local() def get_current_user(): return getattr(_thread_locals, 'user', None) class ThreadLocals(object): """Middleware that