views:

45

answers:

1

Model: http://dpaste.com/96349/

View:

def game_list(request):
        return render_to_response('games/game_list.html',
                                  { 'object_list': GameList.objects.published.all().order_by('position')})

Template:

AttributeError at /games/ 'Manager' object has no attribute 'published'

Would seem my view doesn't like my new manager very much?

+3  A: 

If you're trying to use the published manager instead of the objects manager, you should remove the objects reference from the filter process. Also, the published manager is declared for the Game model, not the GameList model. You'll probably need to refactor how it works slightly.

Edit: Here's something that might be matching with what you're trying to do.

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

Your new manager's filter was changed to reference the related game's status, and the manager was attached to the GameList model instead of Game. The command to use now would be:

GameList.published.all().order_by('position')
Adam
Exactly what I needed, thank you.
Rob B