Po wciśnięciu
python manage.py makemigrations
Wyświetlił mi takie coś
Traceback (most recent call last):
File "C:\Users\kondz\sentiment\manage.py", line 22, in <module>
main()
File "C:\Users\kondz\sentiment\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\__init__.py", line 420, in execute
django.setup()
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\apps\registry.py", line 124, in populate
app_config.ready()
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\contrib\admin\apps.py", line 27, in ready
self.module.autodiscover()
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\contrib\admin\__init__.py", line 50, in autodiscover
autodiscover_modules("admin", register_to=site)
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\utils\module_loading.py", line 58, in autodiscover_modules
import_module("%s.%s" % (app_config.name, module_to_search))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\kondz\sentiment\sentimentapp\admin.py", line 21, in <module>
admin.site.unregister(LogEntry)
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\contrib\admin\sites.py", line 161, in unregister
raise NotRegistered("The model %s is not registered" % model.__name__)
django.contrib.admin.sites.NotRegistered: The model LogEntry is not registered
PS C:\Users\kondz\sentiment> python manage.py makemigrations
Traceback (most recent call last):
File "C:\Users\kondz\sentiment\manage.py", line 22, in <module>
main()
File "C:\Users\kondz\sentiment\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\__init__.py", line 420, in execute
django.setup()
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\apps\registry.py", line 124, in populate
app_config.ready()
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\contrib\admin\apps.py", line 27, in ready
self.module.autodiscover()
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\contrib\admin\__init__.py", line 50, in autodiscover
autodiscover_modules("admin", register_to=site)
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\utils\module_loading.py", line 58, in autodiscover_modules
import_module("%s.%s" % (app_config.name, module_to_search))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\kondz\sentiment\sentimentapp\admin.py", line 21, in <module>
admin.site.unregister(LogEntry)
File "C:\Users\kondz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\contrib\admin\sites.py", line 161, in unregister
raise NotRegistered("The model %s is not registered" % model.__name__)
django.contrib.admin.sites.NotRegistered: The model LogEntry is not registered
admin.py
from django.contrib import admin
from django.db import models
from django.urls import NoReverseMatch
from .models import Słowo, Inzynier
from django.contrib.admin.models import LogEntry
from django.contrib.auth import get_user_model
from django.contrib import admin
from django.contrib.admin.models import LogEntry
from django.utils.html import escape
from django.utils.safestring import mark_safe
from sentimentapp.models import Inzynier
from sentimentapp import models
class SłowoAdmin(admin.ModelAdmin):
list_display = ['slowo', 'jest_negatywne', 'jest_pozytywne']
list_filter = ['jest_negatywne', 'jest_pozytywne']
admin.site.register(Słowo, SłowoAdmin)
admin.site.unregister(LogEntry)
class CustomLogEntry(LogEntry):
inzynier = models.ForeignKey(Inzynier, on_delete=models.CASCADE, null=True, blank=True)
class CustomLogEntryAdmin(admin.ModelAdmin):
date_hierarchy = 'action_time'
readonly_fields = LogEntry._meta.get_all_field_names()
list_filter = ['content_type', 'action_flag', 'user']
search_fields = ['object_repr', 'change_message']
list_display = [
'action_time', 'user', 'content_type', 'object_link', 'action_flag', 'change_message'
]
def object_link(self, obj):
if obj.content_type is not None and obj.object_id is not None:
link = escape(obj.object_repr)
try:
url = obj.get_admin_url()
return mark_safe('<a href="%s">%s</a>' % (url, link))
except NoReverseMatch:
return link
return '-'
object_link.admin_order_field = 'object_repr'
object_link.short_description = 'object'
admin.site.register(LogEntry, CustomLogEntryAdmin)
# Odłącz model LogEntry po zarejestrowaniu niestandardowego modelu
admin.site.unregister(LogEntry)
settings.py
"""
Django settings for sentiment project.
Generated by 'django-admin startproject' using Django 4.2.1.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
AUTH_USER_MODEL = 'sentimentapp.Inzynier'
LEKARZ_LOGIN_URL = 'lekarz_logowanie'
INZYNIER_LOGIN_URL = 'inzynier_logowanie'
LOGIN_REDIRECT_URL = 'strona_glowna'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-%wqr84*3w6^h1ionuwb5&&-vw6)k$0!p&a5!e#$fmfox890-0z'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'sentimentapp',
'templates'
]
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',
]
ROOT_URLCONF = 'sentiment.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'sentiment.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
models.py
from django.conf import settings
from django.db import models
from django.contrib.auth.models import AbstractUser, Group, Permission
from django.contrib.auth import get_user_model
class Lekarz(AbstractUser):
groups = models.ManyToManyField(Group, related_name='lekarz_groups')
user_permissions = models.ManyToManyField(Permission, related_name='lekarz_user_permissions')
specjalizacja = models.TextField()
def __str__(self):
return self.username
class Inzynier(AbstractUser):
groups = models.ManyToManyField(Group, related_name='inzynier_groups')
user_permissions = models.ManyToManyField(Permission, related_name='inzynier_user_permissions')
def __str__(self):
return self.username
class Słowo(models.Model):
slowo = models.CharField(max_length=50, unique=True)
jest_negatywne = models.BooleanField(default=False)
jest_pozytywne = models.BooleanField(default=False)
def __str__(self):
return self.slowo
class Opinia(models.Model):
tresc = models.TextField()
punkty = models.IntegerField()
lekarz = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, related_name='opinie_lekarza', null=True, blank=True)
inzynier = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, related_name='opinie_inzyniera', null=True, blank=True)
def __str__(self):
return self.tresc
class Sentyment(models.Model):
inzynier = models.OneToOneField(get_user_model(), on_delete=models.CASCADE, related_name='sentyment', null=True, blank=True)
total_points = models.IntegerField(default=0)
def __str__(self):
return f"Sentyment dla {self.inzynier}"
ChatGPT powiedział, że niby mam coś zmienić w settings.py oraz admin.py, aby naprawić błąd w migracji, a i tak są błędy.
Co ja muszę zmienić, aby błąd zlikwidować?