Karen,

Thanks for your help.  Here's what I've done:

I've commented out the list_display for GameAdmin and defined a
__unicode__ for game as:

        def __unicode__(self):
                return '%s vs. %s' %  (self.team.name, self.opponent)

That returns values in the admin display as "Team 1 vs. Team 2", etc.,
as we would have hoped.

Uncommenting the list_display as so:
class GameAdmin(admin.ModelAdmin):
        list_display = ('team', 'opponent',)
        search_fields = ('team__name','opponent',)

results in the strange behavior (non-zero count but showing no rows)

changing list display to team__name results in the following error:
'team__name' is not a callable or an attribute of 'GameAdmin' or found
in the model 'Game'.

So now that I copied that and pasted that error message here, I have a
thought: make a callable for Game as:
        def _team_name(self):
             return (self.team.name)
        team_name = property(_team_name)

class GameAdmin(admin.ModelAdmin):
        list_display = ('team_name', 'opponent',)
        search_fields = ('team__name','opponent',)

Everything now displays correctly.  Reading the documentation on
list_display and Abstract classes, I assumed that I could reference
Team elements through the AbstractEvent model.  Apparently, that is
not the case. The callable seems to have solved my problem.

Thanks for your help!
Jim



On Nov 19, 10:01 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 19, 2008 at 9:30 PM, JimR <[EMAIL PROTECTED]> wrote:
>
> > Karen,
>
> > Thanks for the quick response, and sorry, I do have quotes around
> > them, I just mistyped when I added them back in for the purposes of
> > this post.
>
> > Here's the abbreviated Team model, and the corrected Admin Manager.
> > We do not have a __unicode__ method defined for the Team model.
>
> > I've reposted everything for easier reading.
>
> > class Team(models.Model):
> >        name = models.CharField(max_length=50)
> >        org = models.ForeignKey(Organization, related_name='teams')
> >        level = models.CharField(choices=COMPETITIVE_LEVEL, max_length=20)
> >        activity = models.ForeignKey(ActivityDetail)
> >        headcoach = models.ForeignKey(Coach, related_name='teams',
> > blank=True, null=True)
> >        coaches = models.ManyToManyField(Coach, blank=True, null=True)
> >        season = models.ForeignKey(Season, related_name='teams')
> >        is_archive = models.BooleanField(default=False)
> >        division = models.ForeignKey(Division, related_name='teams)
> >       ...
>
> > class AbstractEvent(models.Model):
> >        team = models.ForeignKey(Team)
> >        description = models.TextField(null=True, blank=True)
> >        description_rendered = models.TextField(null=True, blank=True)
> >        when = models.DateTimeField()
> >        where = models.ForeignKey(Address)
> >        created_at = models.DateTimeField(default=datetime.today)
> >        created_by = models.ForeignKey(User)
> >       ...
> >        class Meta:
> >                abstract = True
>
> > class Game(AbstractEvent):
> >        opponent = models.CharField(max_length=128)
> >        minutes_early = models.PositiveIntegerField(null=True,
> > blank=True)
> >        counts_towards_record = models.BooleanField(default=True)
> >        points_for = models.IntegerField(null=True, blank=True)
> >        points_against = models.IntegerField(null=True, blank=True)
> >        ...
>
> > The AdminManager for the Game model is as follows:
>
> > class GameAdmin(admin.ModelAdmin):
> >        list_display = ('team', 'opponent',)
> >        search_fields = ('team', 'opponent',)
> >       ...
>
> Cut and pasting your models & admin def, commenting out all the ForeignKeys
> for models not included, and putting them in a project yields an admin
> change list for Game that shows both the Team (unhelpfully identified as
> "Team object" in the absence of a __unicode__ method in Team) and opponent.
> So, there's something else involved here. I'd advise starting with what
> you've posted here -- since that does display a correct admin, and adding
> things bit by bit to match the full setup you actually have that is not
> working, to see what is leading to the problem.  I've never seen anything
> like what you describe (change list giving a non-zero count but showing no
> rows) so I really have no idea what is causing it for you.
>
> You will need to change the 'team' in search_fields to specify the field of
> Team that you want to search on (such as' team__name').  As you have it an
> attempt to search will likely produce an exception.
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to