Basketball Game has 4 Quarters. I would like Django to auto increment Quarter.number for each Game in Admin, so I don’t have to always correct them manually. Example models.py
class Game(models.Model): name = models.CharField() class Quarter(models.Model): number = models.IntegerField(help_text='quarter number from 1 to 4') game = models.ForeignKey(Game) class Meta: unique_together = ['game', 'number']
So number in Quarter can be 1, 2, 3 or 4 (or more for other sports) and should be set to 1 by default. After saving first quarter for one Game it should suggest number=2 for the next entry of the same Game. The incremented numbers should also get shown correctly in admin.TabularInline if I set Quarter as inline of Game in admin.py (in below code Django would by default show 3 entries for a new Game, but all would have default number=1):
class QuarterInline(admin.TabularInline): model = Quarter class Game(admin.ModelAdmin): inlines = [QuarterInline]
How can I achieve that number gets incremented by default for each game?