Hi,
I have a question regarding the admin interface of django.

My models

class Team(models.Model):
    name = models.CharField(max_length=10)

class Player(models.Model):
    lastname = models.CharField(max_length=60)

class Goal(models.Model):
    game = models.ForeignKey(Game)
    goal_scorer =
models.ForeignKey(Player,related_name='goal_scorer',blank=True,null=True)

class Game(models.Model):
    home_team = models.ForeignKey(Team,related_name='home_team')

class GameRoster(models.Model):
    player = models.ForeignKey(Player)
    game = models.ForeignKey(Game)

Each Goal is scored by a Player in a Game. I'm using a inline form to
insert goals for a game.
The players are somehow connected to the team (gameroster), and
therefore to the game.

I found the place to hook in to limit the choices of player.

class GoalInline(admin.TabularInline):
    model = Goal
    extra = 4

    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        if db_field.name == "goal_scorer":
            kwargs["queryset"] =
Player.objects.filter(gameroster__game=self.game)
            return db_field.formfield(**kwargs)

        return super(GoalInline,
self).formfield_for_foreignkey(db_field, request, **kwargs)


The missing point is now: How to access game, which is connected to
the goal to limit the players?
I tried self.game as you can see, but that doesn't work.
How can I access the model from within this function?

Chris

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to