在经历了几次stackoverflow之后,我仍然没有找到解决这个问题的东西。我希望它只是语法,因为我是新手。
管理:
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)
型号:
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)
错误:类没有类的外键 我正在使用此设置,因为我想轻松地查看团队中的玩家并将团队从一个团队更改为另一个团队(从不在多个团队中)
答案 0 :(得分:0)
移动到团队中的多对多关系并删除了团队成员表:
players = models.ManyToManyField(Player, blank=True, null=True)