我是django的新手,我正在django建立一个板球俱乐部管理网站。有团队,球员,场地和比赛应用。在团队应用程序中。
玩家模型:
07-27 15:11:59.434 17744-17744/com.whatamidoingwithmylife.splitbill E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.whatamidoingwithmylife.splitbill, PID: 17744
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.whatamidoingwithmylife.splitbill/com.whatamidoingwithmylife.splitbill.MenuActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:117)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:31)
at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java:31)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:198)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at com.whatamidoingwithmylife.splitbill.MenuActivity.<init>(MenuActivity.java:48)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
团队模型:
class Players(models.Model):
player_full_name = models.CharField(max_length=40)
player_email = models.EmailField(unique=True)
player_team = models.ManyToManyField(Teams)
匹配模型:
class Teams(models.Model):
team_name = models.CharField(max_length=100)
team_home_ground = models.ForeignKey(Grounds, on_delete=None, null=True, blank=True)
现在,我想添加另一个模型AddMatchRecod提交比赛记录,然后我将基于该模型创建表格。在AddMatchRecod中,我希望有一个字段winning_team字段,以及一个来自AddMatch模型match_team_1和match_team_2的两个字段的下拉列表作为选择。球队表中有很多球队,我只想介绍两个参加比赛的球队。我怎么会得到。
class AddMatch(models.Model):
match_team_1 = models.ForeignKey(Teams, on_delete=models.CASCADE, related_name='match_team1')
match_team_2 = models.ForeignKey(Teams, on_delete=models.CASCADE, related_name='match_team2')
match_ground = models.ForeignKey(Grounds, on_delete=None)
match_date = models.DateField(default=timezone.now)
第二个问题。有一个PlayersRecords模型可以存储玩家数据。有100个玩家,我将如何获得team1和team2的11个或12个玩家,并分别为每个玩家显示PlayerRecord模型字段。
玩家记录模型:
class MatchAddData(models.Model):
team1 = ??
team2 = ??
谢谢。