AttributeError: 'AdminSite' object has no attribute 'Register'
when i go to make migrations and open my admin section to add so dummy info and image I receive the error.
admin.site.Register(Bet, BetAdmin)
What I have done so far is delete and hit return to see if it was indentation mistake on the class.
I also installed pylint to see more details on errors based on the one suggested answers.
pip install pylint-django
then I added to my setttings.json
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
"workbench.colorTheme": "PowerShell ISE",
"python.pythonPath": "C:\\Users\\taylo\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe",
"json.schemas": [
],
"python.linting.pylintArgs": [
"--load-plugins=pylint_django"
],
"[python]": {
}
}
but it didn't seam to solve anything related to issue.
FYI: I did a bunch of searches and view on stack and but solutions seen where for spelling errors ased on the word being spelled incorrectly with q like reqister instead of register is and was not spelled wrong.
the full terminal error
(venv) PS C:\Users\taylo\django\pybet_project> python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\apps\registry.py", line 122, in populate
app_config.ready()
File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\contrib\admin\apps.py", line 24, in ready
self.module.autodiscover()
File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Users\taylo\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\taylo\django\pybet_project\bets\admin.py", line 8, in <module>
admin.site.Register(Bet, BetAdmin)
File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\utils\functional.py", line 225, in inner
return func(self._wrapped, *args)
AttributeError: 'AdminSite' object has no attribute 'Register'
(venv) PS C:\Users\taylo\django\pybet_project>
admin.py
from django.contrib import admin
from .models import Bet
class BetAdmin(admin.ModelAdmin):
list_display = {'home_team', 'away_team', 'home_team_odds', 'draw_odds', 'away_team_odds'}
admin.site.Register(Bet, BetAdmin)
models.py
from django.db import models
class Bet(models.Model):
home_team = models.CharField(max_length=255)
home_team_logo = models.ImageField(upload_to='logos')
away_team = models.CharField(max_length=255)
away_team_logo = models.ImageField(upload_to='logos')
home_team_odds = models.DecimalField(max_digits=3, decimal_places=2)
draw_odds = models.DecimalField(max_digits=3, decimal_places=2)
away_team_odds = models.DecimalField(max_digits=3, decimal_places=2)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('new', views.new, name='new')
]
views.py
from django.shortcuts import render
from .models import Bet
def index(request):
bets = Bet.objects.all()
return render(request, 'bets/index.html', {'bets: bets'})