0

I am trying to reuse an existant Django project, which works just fine, but I encounter an error on a specific part. I'm only using the admin interface with quite a few models. The error is as follow :

Whenever I try to add an object (of this particular model) via the admin, I get :

'NoneType' object has no attribute 'all'
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/myapp/style/add/
Django Version: 1.5.1
Exception Type: AttributeError
Exception Value:    
'NoneType' object has no attribute 'all'
Exception Location: /usr/lib/python2.7/site-packages/django/forms/models.py in __iter__, line 919

I found the "NoneType" in the admin.py :

class StyleForm(forms.ModelForm):

        featured_item = forms.ModelChoiceField(None, required=False)

and in the models.py :

def featured_item_id(self):

    fi_list = FeaturedItem.objects.filter(style=self)

    if fi_list.count() > 0:
        return fi_list[0].item.id
    else:
        return None

I would understand that such an error is possible if the project had never worked and wasn't working at this very moment elsewhere, but this is a functionnal Django project, all I did was migrate it locally, fixing the settings.py accordingly... Could it come from the database not being populated at the moment ?

I would very much appreciate any help, I've been stuck with it for quite a while and it's important that I manage to get past this annoying bug..

Thank you all in advance for your time and advice.

4

1 回答 1

1

将评论标记为将来参考的答案:

可能是一些.pyc工作正常的陈旧文件。虽然看起来很奇怪。你可能想要

forms.ModelChoiceField(FeaturedItem.objects.none(), required=False)
于 2013-05-28T15:14:09.633 回答