Django模型类在经理中是None

时间:2015-02-08 04:33:52

标签: python django django-models uwsgi

我在运行django应用的服务器上遇到了一个非常奇怪的错误。该错误在我的本地开发服务器上无法重现。

我有这个模特和它的经理:

class CardManager(models.Manager):

    def get_by_identifier(self, card_identifier):
        ...
        for possible_suit in Card.SUITS:
            ...

class Card(models.Model):
    objects = CardManager()
    SUITS = ((1, 'Clubs'), ...)

这是错误:

AttributeError at /game/playcard/2/S1/

'NoneType' object has no attribute 'SUITS'

和追溯:

File "local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
    115. response = callback(request, *callback_args, **callback_kwargs)
File "local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
    25. return view_func(request, *args, **kwargs)
File "views.py" in play_card
    155. card = Card.objects.get_by_identifier(card_identifier)
File "models.py" in get_by_identifier
    16. for possible_suit in Card.SUITS:

运行Django 1.5(是的,我知道),Python 2.7和uwsgi

有什么想法吗?因为我无法在我的本地机器上重现它,所以我倾向于特定的uwsgi,但我不知道在哪里看...

谢谢!

1 个答案:

答案 0 :(得分:1)

使用self.model从管理员访问模型:

for possible_suit in self.model.SUITS:
    ...