开发者

django form error : Caught AttributeError while rendering: 'NoneType' object has no attribute 'label'

Model:

class AppUser(models.Model) :
   开发者_JS百科 user = models.ForeignKey(User, unique=True)
    slug = models.SlugField(editable=False, blank=True)
    date_created = models.DateTimeField(editable=False, auto_now_add=True)
    last_updated = models.DateTimeField(editable=False, auto_now=True)
    hobbies = models.CharField(max_length=100, blank=True, null=True)
    education_level = models.CharField(max_length=100, blank=True, null=False)
    identifier = models.CharField(max_length=100, blank=True, null=True, unique=True)

class Student(models.Model):
    appuser = models.ForeignKey(AppUser , unique=True)
    institution = models.ForeignKey(Institution , blank=True, null=False)
    course = models.CharField(max_length=100, blank=True, null=True)
    department = models.ForeignKey(Department, blank=True, null=True)
    institute_email = models.EmailField(blank=True, null=True)
    is_valid = models.BooleanField(default=False)

Forms:

class StudentForm(ModelForm):
    institute_id = forms.CharField()
    institution = forms.ModelChoiceField(queryset=Institution.objects.all())
    course = forms.ChoiceField(choices=COURSE_CHOICES)
    education_level = forms.ChoiceField(choices=EDUCATION_LEVELS)

    class Meta:
        model = Student
        exclude = ('appuser','department', 'is_valid')

Views:

student_formset = inlineformset_factory(AppUser,Student,fields=('institution', \
'course', 'institute_email', 'identifier', 'education_level'),form=StudentForm)

if request.POST:
    student_form = student_formset(request.POST, instance=user)
    if student_form.is_valid():

Template:

<form method='post' action='#student'>
{{ student_form.management_form }}
{% for form in student_form.forms %}
    <p>{{ form}}</p>
{% endfor %}
 </form>

Error:

Caught AttributeError while rendering: 'NoneType' object has no attribute 'label'

Request Method: GET Request URL: http://127.0.0.1:8000/profiles/add_details/ Django Version: 1.2.4 Exception Type: TemplateSyntaxError Exception Value:

Caught AttributeError while rendering: 'NoneType' object has no attribute 'label' .....

Template error .... Caught AttributeError while rendering: 'NoneType' object has no attribute 'label'

It shows problem in template code..

If in template instead of rendering {{form}} we use {{form.as_p}} then it outputs nothing.

Any ideas on above issue??


I believe here:

student_formset = inlineformset_factory(AppUser,Student,fields=('institution', \
'course', 'institute_email', 'identifier', 'education_level'),form=StudentForm)

identifier does not exists... is nothing, none, null etc ... remove it! :) education_level also!

Or, subclass Student to AppUser!

class Student(AppUser):
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜