I'd like to ask for you guidance in the following matter in django:
I am using the following models:
class QItem(models.Model):
isWhat = models.CharField(max_length=100, blank=True, choices=ISWHAT)
slug = models.SlugField(blank=True)
script = models.CharField(max_length=100)
comment = models.TextField(blank=True, null=True)
author = models.ForeignKey(User)
class QuestionSet(QItem):
items = models.ManyToManyField(QItem, blank=True, through='Ordering',related_name="contained")
class Question(QItem):
answerObject = models.OneToOneField("AnswerObject", blank=True, null=True)
and their respective, most basic ModelForms:
class QuestionForm(ModelForm):
class Meta:
model = Question
class QuestionSetForm(ModelForm):
class Meta:
model = QuestionSet
In a view, calling
qset=QuestionFormSet()
print q
works just fine.
However,
q = QuestionForm()
print q
throws
Exception Type: AttributeError
Exception Value: 'NoneType' object has no attribute 'label'
in Django's server. When trying it in the console, I don't get any errors. Edit : Also, modelform_factory(Question) works.
Any ideas why this is the case? Why do similar models behave so differently, and how could I get rid of the error?
Edit : This is the full Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response 100. response = callback(request, *callback_args, **callback_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 25. return view_func(request, *args, **kwargs) File "/Library/WebServer/Documents/dj1/../dj1/esm/views.py" in dashboard 193. print qForm File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/utils/encoding.py" in str 27. return self.unicode().encode('utf-8') File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/forms/forms.py" in unicode 95. return self.as_table() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/forms/forms.py" in as_table 217. errors_on_separate_row = False) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/forms/forms.py" in _html_output 145. bf = BoundField(self, field, name) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/forms/forms.py" in init 398. if self.field.label is None:
Exception Type: AttributeError at /esm/dashboard/ Exception Value: 'NoneType' object has no attribute 'label'