I am getting the following error message when I save the user object. I have searched on the internet for the error message, but I can not find any help. It maybe somthing very obvious that I am missing, but I am not able to find any help available.
Can someone take a look and let me know what the error here is?
File admin.py
from django.contrib.auth.admin import UserAdmin
class UserAdmin(UserAdmin):
list_display = ('username', 'email', 'first_name', 'last_name',
'is_active', roles, login)
list_filter = ('groups',)
def save_model(self, request, obj, form, change):
queryset = MyUser.objects.filter(id=obj.id)
if obj.is_active:
logger.info('User is marked active')
elif not obj.is_active:
logger.info('User is marked inactive')
obj.save()
def add_view(self, *args, **kwargs):
self.inlines = []
return super(UserAdmin, self).add_view(*args, **kwargs)
def change_view(self, request, object_id, form_url='', extra_context=None):
self.inlines = (ProfileInline,)
return super(UserAdmin, self).change_view(request, object_id, form_url, extra_context)
File models.py
class MyUser(User, URLGenerator):
objects = models.Manager() # The default manager.
safe = SafeUserManager()
class Meta:
proxy = True
ordering = ['username']
def __unicode__(self):
return self.get_full_name()
The ERROR I'm getting:
Internal Server Error: /admin/public/myuser/1/change/
Traceback (most recent call last):
File "/dp/app/venv/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 551, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 224, in inner
return view(request, *args, **kwargs)
File "/dp/app/dpapp/public/admin.py", line 364, in change_view
return super(UserAdmin, self).change_view(request, object_id, form_url, extra_context)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1511, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1408, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1440, in _changeform_view
if form.is_valid():
File "/dp/app/venv/local/lib/python2.7/site-packages/django/forms/forms.py", line 183, in is_valid
return self.is_bound and not self.errors
File "/dp/app/venv/local/lib/python2.7/site-packages/django/forms/forms.py", line 175, in errors
self.full_clean()
File "/dp/app/venv/local/lib/python2.7/site-packages/django/forms/forms.py", line 386, in full_clean
self._post_clean()
File "/dp/app/venv/local/lib/python2.7/site-packages/django/forms/models.py", line 413, in _post_clean
self.instance.full_clean(exclude=exclude, validate_unique=False)
File "/dp/app/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 1235, in full_clean
self.clean()
File "/dp/app/venv/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 349, in clean
self.email = self.__class__.objects.normalize_email(self.email)
AttributeError: 'Manager' object has no attribute 'normalize_email'
Your User object doesn't have the manager method normalize_email. Try changing your user's manager to
objects = BaseUserManager()
which you can import in django.contrib.auth.base_user
Related
Notification are already working in the view class. But not working in admin.py
I do send the puh notification after the save record in save_model. but not working here is my method
class EventAdmin(admin.ModelAdmin):
list_display = ('event_name', 'event_type', 'event_city', 'event_organizer', 'start_date',
'start_time', 'end_date', 'end_time', 'is_approved', 'is_active', 'created_at')
fields = ('main_image', 'event_name', 'event_organizer', 'event_type', 'event_city', 'event_tag', 'event_address', 'event_description',
'event_notes', 'start_date', 'start_time', 'end_date', 'end_time', 'age_max', 'age_min', 'event_lat', 'event_lng', 'website', 'is_approved', 'is_active', 'created_at')
def save_model(self, request, instance, form, change):
user = request.user
instance = form.save(commit=False)
if not change or not instance.created_by:
instance.created_by = user
# Here is notification class
notifiClass = Notifications()
notifiClass.sendNotifications(instance)
else:
instance.is_updated = True
instance.modified_by = user
instance.save()
form.save_m2m()
return instance
here is my Notification class in admin.py
class Notifications(object):
def sendNotifications(self, data):
users = models.NewEventNotification.objects.all().filter(is_notify=1)
serializer = NewEventNotificationSerializer(users, many=True)
tokens = []
for user in serializer.data:
tokens.append(user['user_token'])
if tokens:
push_service = FCMNotification(api_key=api_key)
message_title = "New Event"
message_body = data
result = push_service.notify_multiple_devices(
registration_ids=tokens, message_title=message_title, message_body=message_body)
print(result)
this shows the result in browser
TypeError at /admin/events/event/add/
Object of type Event is not JSON serializable
Request Method: POST
Request URL: http://192.168.0.104:8000/admin/events/event/add/
Django Version: 2.1.5
Exception Type: TypeError
Exception Value:
Object of type Event is not JSON serializable
Exception Location: C:\Python\Python37-32\lib\json\encoder.py in default, line 179
Python Executable: C:\Python\Python37-32\python.exe
Python Version: 3.7.4
Python Path:
['D:\\python\\emsbackend',
'C:\\Python\\Python37-32\\python37.zip',
'C:\\Python\\Python37-32\\DLLs',
'C:\\Python\\Python37-32\\lib',
'C:\\Python\\Python37-32',
'C:\\Users\\laptop '
'genration\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Python\\Python37-32\\lib\\site-packages',
'C:\\Python\\Python37-32\\lib\\site-packages\\pip-19.2.3-py3.7.egg']
Server time: Fri, 20 Dec 2019 18:32:51 +0500
and in console
Internal Server Error: /admin/events/event/add/
Traceback (most recent call last):
File "C:\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Python\Python37-32\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python\Python37-32\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python\Python37-32\lib\site-packages\django\contrib\admin\options.py", line 604, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Python\Python37-32\lib\site-packages\django\utils\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Python\Python37-32\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Python\Python37-32\lib\site-packages\django\contrib\admin\sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "C:\Python\Python37-32\lib\site-packages\django\contrib\admin\options.py", line 1637, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "C:\Python\Python37-32\lib\site-packages\django\utils\decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Python\Python37-32\lib\site-packages\django\utils\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Python\Python37-32\lib\site-packages\django\contrib\admin\options.py", line 1525, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Python\Python37-32\lib\site-packages\django\contrib\admin\options.py", line 1564, in _changeform_view
self.save_model(request, new_object, form, not add)
File "D:\python\emsbackend\events\admin.py", line 296, in save_model
notifiClass.sendNotifications(instance)
File "D:\python\emsbackend\events\admin.py", line 382, in sendNotifications
registration_id=tokens[0], message_title=message_title, message_body=message_body)
File "C:\Python\Python37-32\lib\site-packages\pyfcm\fcm.py", line 113, in notify_single_device
**extra_kwargs
File "C:\Python\Python37-32\lib\site-packages\pyfcm\baseapi.py", line 299, in parse_payload
return self.json_dumps(fcm_payload)
File "C:\Python\Python37-32\lib\site-packages\pyfcm\baseapi.py", line 120, in json_dumps
ensure_ascii=False
File "C:\Python\Python37-32\lib\json\__init__.py", line 238, in dumps
**kw).encode(obj)
File "C:\Python\Python37-32\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Python\Python37-32\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Python\Python37-32\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Event is not JSON serializable
after searching got this solution. on notification class
# Here is notification class
notifiClass = Notifications()
notifiClass.sendNotifications(instance)
change to this
# make serializer class of that event
serializer = eventSerializer(instance)
notifiClass = Notifications()
notifiClass.sendNotifications(serializer)
I have written a model as follows:
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=100)
title = models.CharField(max_length=3)
birth_date = models.DateField(blank=True, null=True)
And my modeladmin is as follows:
from django.contrib import admin
class AuthorAdmin(admin.ModelAdmin):
fields = ('name', 'title', 'view_birth_date')
def view_birth_date(self, obj):
return obj.birth_date
view_birth_date.empty_value_display = '-empty-'
As documented in django 2.1 https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.empty_value_display, I am trying to do this but its not working.
Its gives me fielderror. Even I didn't understand its purpose.
My traceback:
Traceback (most recent call last):
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\contrib\admin\options.py", line 703, in get_form
return modelform_factory(self.model, **defaults)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\forms\models.py", line 551, in modelform_factory
return type(form)(class_name, (form,), form_class_attrs)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\forms\models.py", line 266, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (view_birth_date) specified for Author
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\contrib\admin\options.py", line 604, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\utils\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\contrib\admin\sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\contrib\admin\options.py", line 1639, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\utils\decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\utils\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\contrib\admin\options.py", line 1525, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\contrib\admin\options.py", line 1554, in _changeform_view
ModelForm = self.get_form(request, obj, change=not add)
File "C:\Users\monikat\Envs\django_training\lib\site-packages\django\contrib\admin\options.py", line 707, in get_form % (e, self.__class__.__name__)
django.core.exceptions.FieldError: Unknown field(s) (view_birth_date) specified for Author. Check fields/fieldsets/exclude attributes of class AuthorAdmin.
Does anyone know why this error is coming?
The problem is that you have defined view_birth_date in the fields attribute of model admin class.
Since it is not present in your db model, it is giving error. Such custom fields will work for list_display, in which you can fetch the value from a method as you have done above, see the docs.
Now if you want some custom field to display on the add/change page , you have to create a custom form and there you can define your custom fields.
If the custom field is just for representation , you can define it as readonly as :
class AuthorAdmin(admin.ModelAdmin):
fields = ('name', 'title', 'view_birth_date')
readonly_fields = ['view_birth_date']
def view_birth_date(self, obj):
return obj.title
view_birth_date.empty_value_display = '-empty-'
Hope it helps!
I have reviewed many questions/answers for hours and applied many techniques but I couldn't pass the user id to the form init() method, it always gives errors like "init() got an unexpected keyword argument 'request'". Anyone knows the reason?
Form, updated as requested in the comment:
class ChildChoreForm(ModelForm):
class Meta:
model = ChildChore
exclude = ('child',)
fields = '__all__'
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(ChildChoreForm, self).__init__(*args, **kwargs)
self.fields['chore'].queryset = Chore.objects.filter(created_by=self.request.user)
ChildChoreFormSet = inlineformset_factory(Child, ChildChore, form=ChildChoreForm, extra=1)
View:
class ChildChoreUpdate(UpdateView):
model = Child
success_url = reverse_lazy('children-list')
form_class = ChildChoreFormSet
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
if hasattr(self, 'object'):
kwargs.update({'request': self.request})
return kwargs
The Errors I'm getting after opening the updaet web page:
Internal Server Error: /chore/children/23
Traceback (most recent call last):
File "C:\Python\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Python\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django\views\generic\base.py", line 69, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django\views\generic\base.py", line 89, in dispatch
return handler(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django\views\generic\edit.py", line 190, in get
return super().get(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django\views\generic\edit.py", line 133, in get
return self.render_to_response(self.get_context_data())
File "C:\Python\py_projects\children_chores\chore\views.py", line 202, in get_context_data
data = super(ChildChoreUpdate, self).get_context_data(**kwargs )
File "C:\Python\lib\site-packages\django\views\generic\edit.py", line 66, in get_context_data
kwargs['form'] = self.get_form()
File "C:\Python\lib\site-packages\django\views\generic\edit.py", line 33, in get_form
return form_class(**self.get_form_kwargs())
File "C:\Python\lib\site-packages\django\forms\models.py", line 898, in __init__
super().__init__(data, files, prefix=prefix, queryset=qs, **kwargs)
File "C:\Python\lib\site-packages\django\forms\models.py", line 569, in __init__
super().__init__(**defaults)
TypeError: __init__() got an unexpected keyword argument 'request'
Internal Server Error: /chore/children/23
Traceback (most recent call last):
File "C:\Python\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Python\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django\views\generic\base.py", line 69, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django\views\generic\base.py", line 89, in dispatch
return handler(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django\views\generic\edit.py", line 190, in get
return super().get(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django\views\generic\edit.py", line 133, in get
return self.render_to_response(self.get_context_data())
File "C:\Python\py_projects\children_chores\chore\views.py", line 202, in get_context_data
data = super(ChildChoreUpdate, self).get_context_data(**kwargs )
File "C:\Python\lib\site-packages\django\views\generic\edit.py", line 66, in get_context_data
kwargs['form'] = self.get_form()
File "C:\Python\lib\site-packages\django\views\generic\edit.py", line 33, in get_form
return form_class(**self.get_form_kwargs())
File "C:\Python\lib\site-packages\django\forms\models.py", line 898, in __init__
super().__init__(data, files, prefix=prefix, queryset=qs, **kwargs)
File "C:\Python\lib\site-packages\django\forms\models.py", line 569, in __init__
super().__init__(**defaults)
TypeError: __init__() got an unexpected keyword argument 'request'
The problem is that you have set up your form to accept a request argument in __init__, but you are initialising a formset, not a form. You need to modify the formset to accept that same argument and pass it to the forms in the formset:
# First define a base class that overrides __init__ and get_form_kwargs
from django.forms import BaseFormSet
class BaseChildChoreFormSet(BaseFormSet):
def __init__(self, *args, **kwargs):
# Handle the request argument that you are passing on init
self.request = kwargs.pop('request', None)
super().__init__(*args, **kwargs)
def get_form_kwargs(self, index):
kwargs = super().get_form_kwargs(index)
# Add request to the kwargs that are passed to the form on init
kwargs['request'] = self.request
return kwargs
# Now set up your formset using this class
ChildChoreFormSet = inlineformset_factory(
Child, ChildChore, form=ChildChoreForm, formset=BaseChildChoreFormSet, extra=1)
Using Django 1.10 I have no problem using my custom backend to login (not a custom user just the auth) but in 1.11rc1 I get the following exception:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/login/?next=/admin/
Django Version: 1.11rc1
Exception Type: FieldError
Exception Value:
Cannot resolve keyword 'request' into field. Choices are: clientcontact, crudevent, date_joined, email, <...just more fields>
The backend:
def authenticate(self, **kwargs):
if kwargs:
username = kwargs.pop("username", None)
if username:
username_or_email = Q(username=username) | Q(email=username)
password = kwargs.pop("password", None)
try:
user = User.objects.get(username_or_email, **kwargs)
except User.DoesNotExist:
pass
else:
if user.check_password(password):
return user
else:
...
In settings.py:
AUTHENTICATION_BACKENDS = ('base_app.auth_backend.JbcBackend', 'guardian.backends.ObjectPermissionBackend',)
I haven't been able to find anything, if someone could point me in the right direction that would be great.
Here is the full Traceback:
Traceback:
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/channels/handler.py" in process_exception_by_middleware
237. return super(AsgiHandler, self).process_exception_by_middleware(exception, request)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/contrib/admin/sites.py" in login
393. return LoginView.as_view(**defaults)(request)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/contrib/auth/views.py" in dispatch
90. return super(LoginView, self).dispatch(request, *args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/views/generic/edit.py" in post
182. if form.is_valid():
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/forms/forms.py" in is_valid
183. return self.is_bound and not self.errors
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/forms/forms.py" in errors
175. self.full_clean()
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/forms/forms.py" in full_clean
385. self._clean_form()
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/forms/forms.py" in _clean_form
412. cleaned_data = self.clean()
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/contrib/auth/forms.py" in clean
187. self.user_cache = authenticate(self.request, username=username, password=password)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/contrib/auth/__init__.py" in authenticate
100. user = backend.authenticate(*args, **credentials)
File "/home/mat/PycharmProjects/jbc_services/base_app/auth_backend.py" in authenticate
19. user = User.objects.get(username_or_email, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/db/models/manager.py" in manager_method
85. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/db/models/query.py" in get
370. clone = self.filter(*args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/db/models/query.py" in filter
781. return self._filter_or_exclude(False, *args, **kwargs)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/db/models/query.py" in _filter_or_exclude
799. clone.query.add_q(Q(*args, **kwargs))
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/db/models/sql/query.py" in add_q
1260. clause, _ = self._add_q(q_object, self.used_aliases)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/db/models/sql/query.py" in _add_q
1286. allow_joins=allow_joins, split_subq=split_subq,
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/db/models/sql/query.py" in build_filter
1164. lookups, parts, reffed_expression = self.solve_lookup_type(arg)
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/db/models/sql/query.py" in solve_lookup_type
1044. _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/home/mat/.virtualenvs/jbcarcenv/lib/python3.6/site-packages/django/db/models/sql/query.py" in names_to_path
1362. "Choices are: %s" % (name, ", ".join(available)))
Exception Type: FieldError at /admin/login/
Exception Value: Cannot resolve keyword 'request' into field. Choices are: clientcontact, crudevent, date_joined, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, logged_in_user, loginevent, password, thirdpartycontact, user_bookmarks, user_permissions, user_preferences, username, userobjectpermission
try:
user = User.objects.get(username_or_email)
# The user is found, now check if the password matches
if user.check_password(password):
return user
except User.DoesNotExist:
pass
...
I have a very simple ModelForm subclass:
class UserPrefsForm(forms.ModelForm):
class Meta:
model = User
fields = ['first_name','last_name','username']
When I try to save the form in my view (only the post function here):
def post(self, request):
userform = UserPrefsForm(request.POST)
context = self.get_context_data()
if userform.is_valid():
userform.save()
else:
context['errors'] = True
return render(request,self.template_name,context)
I got this error:
AttributeError at /prefs
'super' object has no attribute 'error_messages'
Traceback:
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/braces/views.py" in dispatch
107. request, *args, **kwargs)
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
86. return handler(request, *args, **kwargs)
File "/home/tonjo/prj/tuned_prj/tuned_django/graph/views.py" in post
147. if userform.is_valid():
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/forms.py" in is_valid
126. return self.is_bound and not bool(self.errors)
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/forms.py" in _get_errors
117. self.full_clean()
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
274. self._post_clean()
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/models.py" in _post_clean
344. self.validate_unique()
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/forms/models.py" in validate_unique
353. self.instance.validate_unique(exclude=exclude)
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/db/models/base.py" in validate_unique
731. errors = self._perform_unique_checks(unique_checks)
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/db/models/base.py" in _perform_unique_checks
831. errors.setdefault(key, []).append(self.unique_error_message(model_class, unique_check))
File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/django/db/models/base.py" in unique_error_message
882. return field.error_messages['unique'] % {
File "/home/tonjo/venv/tuned/src/neo4django/neo4django/utils.py" in __getattr__
303. return getattr(target, name)
I understand is the missing error_messages... Am I forced to define them?