# Auto increment field that is part of unique\_together in Django admin

**URL:** <https://forum.djangoproject.com/t/auto-increment-field-that-is-part-of-unique-together-in-django-admin/608>\
**Category:** Using Django\
**Created:** [December 12, 2019, 4:18pm UTC](https://forum.djangoproject.com/t/auto-increment-field-that-is-part-of-unique-together-in-django-admin/608 "2019-12-12T16:18:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kljuka](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kljuka](https://forum.djangoproject.com/u/kljuka)\
**Post date:** [December 12, 2019, 4:18pm UTC](https://forum.djangoproject.com/t/auto-increment-field-that-is-part-of-unique-together-in-django-admin/608/1 "2019-12-12T16:18:59Z")

</div>

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

```auto
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):

```auto
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?

---

<div class="post-metadata">

**Author:** ![chengc](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@chengc](https://forum.djangoproject.com/u/chengc)\
**Post date:** [December 12, 2019, 11:09pm UTC](https://forum.djangoproject.com/t/auto-increment-field-that-is-part-of-unique-together-in-django-admin/608/2 "2019-12-12T23:09:13Z")

</div>

If it’s ok to create the quarters in advance, create them when a new game created (override Game.save() ), probably easier than other solutions.
