From 0fd8396b36848555998f1405727b3ab05ae7c222 Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Mon, 8 Feb 2021 11:06:49 -0500 Subject: [PATCH] feat: added competitor inline to team admin view --- innovate/admin.py | 12 +++++++++++- .../migrations/0002_auto_20210208_1549.py | 19 +++++++++++++++++++ innovate/models.py | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 innovate/migrations/0002_auto_20210208_1549.py diff --git a/innovate/admin.py b/innovate/admin.py index d4452aa..503719a 100644 --- a/innovate/admin.py +++ b/innovate/admin.py @@ -15,4 +15,14 @@ admin_site.register(User) admin_site.register(Group) admin_site.register(Competitor) -admin_site.register(Team) \ No newline at end of file + +class CompetitorInline(admin.TabularInline): + model = Competitor + +class TeamAdmin(admin.ModelAdmin): + inlines = [ + CompetitorInline, + ] + + +admin_site.register(Team, TeamAdmin) \ No newline at end of file diff --git a/innovate/migrations/0002_auto_20210208_1549.py b/innovate/migrations/0002_auto_20210208_1549.py new file mode 100644 index 0000000..3291e2c --- /dev/null +++ b/innovate/migrations/0002_auto_20210208_1549.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.6 on 2021-02-08 15:49 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('innovate', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='competitor', + name='team', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='competitors', to='innovate.team'), + ), + ] diff --git a/innovate/models.py b/innovate/models.py index 50f150f..9133dea 100644 --- a/innovate/models.py +++ b/innovate/models.py @@ -25,7 +25,7 @@ class Competitor(models.Model): email = models.EmailField(max_length = 254) is_leader = models.BooleanField(default=False) - team = models.ForeignKey(Team, on_delete=models.CASCADE) + team = models.ForeignKey(Team, related_name="competitors", on_delete=models.CASCADE) class Meta: verbose_name = "Competitor"