Django NameError: name XXXX is not defined
Here is the error from the error log file in Elastic Beanstalk:
File "/var/app/current/content/admin.py", line 5, in <module>
class CoursesAdmin(admin.ModelAdmin):
File "/var/app/current/content/admin.py", line 6, in CoursesAdmin
form = CoursesAdminForm
^^^^^^^^^^^^^^^^
NameError: name 'CoursesAdminForm' is not defined
I had a hard time getting this to work on my localhost, which is working perfectly now, but 'EB deploy' is failing and giving me the above error. Here is the relevant admin.py code:
from django.contrib import admin
from .models import Courses
from .forms import CoursesAdminForm
class CoursesAdmin(admin.ModelAdmin):
form = CoursesAdminForm
list_display = ('courseName', 'languagePlan',
'level', 'active', 'tdColour')
And here is the relevant code from the content.forms.py file:
from django import forms
from .models import Courses, LanguagePlan
class CoursesAdminForm(forms.ModelForm):
languageplanqueryset = LanguagePlan.objects.all()
courseName = forms.CharField(label='Course Name', max_length=255)
languagePlan = forms.ModelChoiceField(required=True,
queryset=languageplanqueryset, empty_label="Select One", to_field_name=
"id")
level = forms.IntegerField(label='Level')
active = forms.BooleanField(label='Active', initial=True)
tdColour = forms.CharField(label='TD Colour', max_length=80)
class Meta:
model = Courses
fields = ('courseName', 'languagePlan',
'level', 'active', 'tdColour')
I am really at a loss here. It is working just fine on localhost, and this error is very difficult to troubleshoot with the log not giving any clues.