Pergunta

After going through several stackoverflows I still have yet to find something that solves this. I'm hoping it's just syntax as I'm a novice.

Admin:

from django.contrib import admin
from team_editor.models import Player, Team, TeamMembers

class PlayerInline(admin.StackedInline):
      model = Player

class TMAdmin(admin.ModelAdmin):
      inlines = (PlayerInline,)

# Register your models here.
admin.site.register(Team)
admin.site.register(Player)
admin.site.register(TeamMembers, TMAdmin)

Models:

class Player(models.Model):
    firstName = models.CharField(max_length=30)
    lastName = models.CharField(max_length=30)

class Team(models.Model):
    teamName = models.CharField(max_length=30, unique=True)

class TeamMembers(models.Model):
    team = models.ForeignKey(Team)
    player = models.ForeignKey(Player, unique=True)

Error: class has no foreign key to class I am using this setup since I want to view players on a team easily and change teams from one team to another (never on multiple)

Foi útil?

Solução

Moved to many to many relation in team and dropped teammember table:

    players = models.ManyToManyField(Player, blank=True, null=True)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top