I am following the Coursera Course on Django as well as the Django tutorial. The Coursera course runs on Pythonanwhere. Now I came up with idea to run it on my MacAir. Thus I created a Conda environment and followed all the steps as for Pythonanywhere. But whenever I run anything like "python manage.py ...." I get this error:
AttributeError: 'Choices' object has no attribute 'model'
edit:
Traceback (most recent call last):
File "manage.py", line 21, in main()
File "manage.py", line 17, in main execute_from_command_line(sys.argv)
File "/opt/anaconda3/envs/Django/lib/python3.6/sitepackages/django/core/management/init.py", line 401, in execute_from_command_line utility.execute().
File "/opt/anaconda3/envs/Django/lib/python3.6/site-packages/django/core/management/init.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/anaconda3/envs/Django/lib/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv self.execute(*args, **cmd_options)
File "/opt/anaconda3/envs/Django/lib/python3.6/site-packages/django/core/management/base.py", line 369, in execute output = self.handle(*args, **options)
File "/opt/anaconda3/envs/Django/lib/python3.6/site-packages/django/core/management/commands/check.py", line 64, in handle fail_level=getattr(checks, options['fail_level']),
File "/opt/anaconda3/envs/Django/lib/python3.6/site-packages/django/core/management/base.py", line 395, in check include_deployment_checks=include_deployment_checks,
File "/opt/anaconda3/envs/Django/lib/python3.6/site-packages/django/core/management/base.py", line 382, in _run_checks return checks.run_checks(**kwargs)
File "/opt/anaconda3/envs/Django/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks new_errors = check(app_configs=app_configs)
File "/opt/anaconda3/envs/Django/lib/python3.6/site packages/django/contrib/admin/checks.py", line 53, in check_admin_app errors.extend(site.check(app_configs))
File "/opt/anaconda3/envs/Django/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 82, in check if modeladmin.model._meta.app_config in app_configs:
AttributeError: 'Choice' object has no attribute 'model'
After researching I finally went from file to file and made a copy paste (except one or two). I even downgraded my Python version from 3.8 to 3.6.3. Didn't help.
I checked for typos and finally did copy-paste. Nothin' :-(
And this my polls/model.py:
from django.db import models
import datetime
from django.utils import timezone
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
edit 2: polls/admin.py
from django.contrib import admin
# Register your models here.
from .models import Question, Choice
admin.site.register(Question, Choice)
In the meantime I changed the name "Choice" to "Choices" just to get the error message:
AttributeError: 'Choices' object has no attribute 'model'
I am quite sure that it is a simple error but I cannot find the solution :-(
Thanks.
ModelAdmin
you defined forChoice
. – Willem Van Onsem