Django prefilled Admin Tabular Inline

My goal is that the first column of my tabular inline sheet is filled with data from another table. I've attached a screenshot where you can see that for tablename=game I want to insert the game number (eg. 1), the metric (e.g time), the player_names and the values (-> scores) per player. Number and metric applies to the hole game. Each game within Table=Game shall contain

  • number
  • metric
  • player_1:name and score
  • player_2:name and score ... and so on.

The player names are stored in a table called players. Is there a way to pre-fill the first row of my tabular inline with my player_names. Otherwise i have to write it down for each game.

Django admin panel_tabularInline

I've created several models in

class Game(models.Model):
    player_name = models.CharField(max_length=30)

class Game (models.Model):
    NUMBER = (
        (1, 1),
        (2, 2),
        (3, 3),
        (4, 4),
        (5, 5),
        (6, 6))
    METRIC = (
        ('Kills', 'Kills'),
        ('Time', 'Time'),
        ('Deaths', 'Deaths')
    number = models.BigIntegerField(default=1, choices=NUMBER)
    metric = models.CharField(max_length=30, choices=METRIC)

class GameItem (models.Model): 

    value = models.CharField(max_length=30)
    game = models.ForeignKey(Game, on_delete=models.CASCADE)

    def __str__(self):

This is my file:

from django.contrib import admin
from .models import *

class GameItemInline(admin.TabularInline):
    model = GameItem
    extra = 6 #I've got 6 players atm.

class GameAdmin(admin.ModelAdmin):
    inlines = [GameItemInline]
    class Meta:
        model = Game, GameAdmin)
Back to Top