So after fixing some minor typos of your example-code and importing all necessary modules for execution i keep getting this at the line of the .aggregate-statement:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/employees/show.html
Django Version: 4.1.7
Python Version: 3.11.2
Installed Applications:
[‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘django.utils.timezone’,
‘django.template’,
‘django_bootstrap_icons’,
‘django_bootstrap5’,
‘django_mysql’,
‘fontawesomefree’,
‘drop_down’,
‘accounts’,
‘employees’]
Installed Middleware:
[‘django.middleware.security.SecurityMiddleware’,
‘django.contrib.sessions.middleware.SessionMiddleware’,
‘django.middleware.common.CommonMiddleware’,
‘django.middleware.csrf.CsrfViewMiddleware’,
‘django.contrib.auth.middleware.AuthenticationMiddleware’,
‘django.contrib.messages.middleware.MessageMiddleware’,
‘django.middleware.clickjacking.XFrameOptionsMiddleware’]
Traceback (most recent call last):
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\core\handlers\exception.py”, line 56, in inner
response = get_response(request)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\core\handlers\base.py”, line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\contrib\auth\decorators.py”, line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File “C:\Users\User\PycharmProjects\klinikXdatabase\employees\views.py”, line 132, in show
).aggregate(total_duration=Sum(‘duration_days’)).values(‘total_duration’)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\query.py”, line 605, in aggregate
return query.get_aggregation(self.db, kwargs)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\sql\query.py”, line 544, in get_aggregation
result = compiler.execute_sql(SINGLE)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\sql\compiler.py”, line 1385, in execute_sql
sql, params = self.as_sql()
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\sql\compiler.py”, line 1919, in as_sql
).as_sql(with_col_aliases=True)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\sql\compiler.py”, line 618, in as_sql
self.compile(self.where) if self.where is not None else (“”, )
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\sql\compiler.py”, line 506, in compile
sql, params = node.as_sql(self, self.connection)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\sql\where.py”, line 112, in as_sql
sql, params = compiler.compile(child)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\sql\compiler.py”, line 506, in compile
sql, params = node.as_sql(self, self.connection)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\fields\related_lookups.py”, line 185, in as_sql
return super().as_sql(compiler, connection)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\lookups.py”, line 357, in as_sql
return super().as_sql(compiler, connection)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\lookups.py”, line 225, in as_sql
rhs_sql, rhs_params = self.process_rhs(compiler, connection)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\lookups.py”, line 118, in process_rhs
sql, params = compiler.compile(value)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\sql\compiler.py”, line 506, in compile
sql, params = node.as_sql(self, self.connection)
File “C:\Users\User\PycharmProjects\klinikXdatabase\venv\Lib\site-packages\django\db\models\expressions.py”, line 838, in as_sql
raise ValueError(
Exception Type: ValueError at /employees/show.html
Exception Value: This queryset contains a reference to an outer query and may only be used in a subquery.