Sorry, okay, here it is.
AttributeError at /admin/accounts/user/1/change/
'User' object has no attribute 'user'
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/accounts/user/1/change/
Django Version: 4.2.2
Exception Type: AttributeError
Exception Value:
'User' object has no attribute 'user'
Exception Location: D:\Sass\F3\accounts\models.py, line 7, in file_upload_path
Raised during: django.contrib.admin.options.change_view
Python Executable: D:\Sass\F3\venv\Scripts\python.exe
Python Version: 3.11.1
Python Path:
['D:\\Sass\\F3',
'C:\\Users\\Dell\\AppData\\Local\\Programs\\Python\\Python311\\python311.zip',
'C:\\Users\\Dell\\AppData\\Local\\Programs\\Python\\Python311\\DLLs',
'C:\\Users\\Dell\\AppData\\Local\\Programs\\Python\\Python311\\Lib',
'C:\\Users\\Dell\\AppData\\Local\\Programs\\Python\\Python311',
'D:\\Sass\\F3\\venv',
'D:\\Sass\\F3\\venv\\Lib\\site-packages']
Server time: Sun, 25 Jun 2023 09:58:19 +0000
Traceback Switch to copy-and-paste view
D:\Sass\F3\venv\Lib\site-packages\django\core\handlers\exception.py, line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\core\handlers\base.py, line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\contrib\admin\options.py, line 688, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\utils\decorators.py, line 134, in _wrapper_view
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\views\decorators\cache.py, line 62, in _wrapper_view_func
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\contrib\admin\sites.py, line 242, in inner
return view(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\contrib\admin\options.py, line 1889, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\utils\decorators.py, line 46, in _wrapper
return bound_method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\utils\decorators.py, line 134, in _wrapper_view
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\contrib\admin\options.py, line 1747, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\contrib\admin\options.py, line 1798, in _changeform_view
self.save_model(request, new_object, form, not add)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\contrib\admin\options.py, line 1227, in save_model
obj.save()
^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\contrib\auth\base_user.py, line 76, in save
super().save(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\db\models\base.py, line 814, in save
self.save_base(
^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\db\models\base.py, line 877, in save_base
updated = self._save_table(
…
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\db\models\base.py, line 981, in _save_table
values = [
…
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\db\models\base.py, line 985, in <listcomp>
(getattr(self, f.attname) if raw else f.pre_save(self, False)),
^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\db\models\fields\files.py, line 317, in pre_save
file.save(file.name, file.file, save=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\db\models\fields\files.py, line 92, in save
name = self.field.generate_filename(self.instance, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\venv\Lib\site-packages\django\db\models\fields\files.py, line 332, in generate_filename
filename = self.upload_to(instance, filename)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
Local vars
D:\Sass\F3\accounts\models.py, line 7, in file_upload_path
from django.db import models
# import abstract user
from django.contrib.auth.models import AbstractUser
# when using file upload path, the error appears when editing profile
def file_upload_path(instance, filename):
return f'user-{instance.user.id}/images/{filename}'
^^^^^^^^^^^^^ …
# DEFINE OUR CUSTOM USER
class User(AbstractUser):
class Role(models.TextChoices):
ADMIN = 'ADMIN', 'Admin'
OWNER = 'OWNER', 'Owner'
Local vars
This is just profile edit page, where i want users to be able to edit their profile. This error appears only when new image is being uploaded…