Django模型类在manager中没有

时间:2021-01-14 19:23:38

I'm getting a very weird error on my server running a django app. The error is not reproducable on my local development server.

在运行django应用程序的服务器上,我得到了一个非常奇怪的错误。这个错误在本地开发服务器上无法复制。

I have this model and it's manager:

我有这个模型,它是经理:

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'), ...)

This is the error:

这是错误的:

AttributeError at /game/playcard/2/S1/

'NoneType' object has no attribute 'SUITS'

and a traceback:

和回溯:

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:

Running Django 1.5 (yea, I know), Python 2.7 and uwsgi

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

Any ideas? I'm leaning towards something uwsgi specific since I can't reproduce it on my local machine, but I wouldn't have any clue where to look...

什么好主意吗?因为我无法在本地机器上复制它,所以我倾向于一些uwsgi特有的东西,但我不知道去哪里看……

Thanks!

谢谢!

1 个解决方案

#1


1  

Use self.model to access the model from the manager:

使用自我。模型从管理器访问模型:

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

#1


1  

Use self.model to access the model from the manager:

使用自我。模型从管理器访问模型:

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