型号:http://dpaste.com/96349/
查看:
def game_list(request):
return render_to_response('games/game_list.html',
{ 'object_list': GameList.objects.published.all().order_by('position')})模板:
位于/ AttributeError / 'Manager‘对象的游戏没有'published’属性
我的观点似乎不太喜欢我的新经理?
发布于 2009-09-21 16:25:25
如果您尝试使用发布的管理器而不是对象管理器,则应该从过滤器过程中删除对象引用。此外,发布的管理器是为游戏模型声明的,而不是GameList模型。您可能需要稍微重构它的工作方式。
编辑:这里有一些可能与你正在尝试做的事情相匹配的东西。
from django.db import models
class GamePublishedManager(models.Manager):
use_for_related_fields = True
def get_query_set(self):
return super(GamePublishedManager, self).get_query_set().filter(game__status='p')
STATUS_CHOICES = (
('d', 'Draft'),
('p', 'Published'),
('w', 'Withdrawn'),
)
class Game(models.Model):
name = models.CharField(max_length=200)
status = models.CharField(max_length=1, choices=STATUS_CHOICES)
def __unicode__(self):
return self.name
class GameList(models.Model):
game = models.ForeignKey(Game)
position = models.IntegerField()
objects = models.Manager()
published = GamePublishedManager()
def __unicode__(self):
return self.game.name您的新经理的过滤器已更改为引用相关游戏的状态,并且经理被附加到GameList模型,而不是游戏。现在要使用的命令是:
GameList.published.all().order_by('position')https://stackoverflow.com/questions/1455291
复制相似问题