Add incrementing integer to queryset each time an object is touched in Django

Add incrementing integer to queryset each time an object is touched in Django

I'm trying to add an incrementing integer, in this case a unique sequence number ranging from [1,n] where n is the number of sequences in the given schedule.

I'm trying to add an incrementing integer, in this case a unique sequence number ranging from [1,n] where n is the number of sequences in the given schedule.

As the sequences will get updated regularly I am wondering what would be the most efficient way to loop through the following

Sequence.objects.filter(schedule=schedule).order_by('start', 'id')

and assign the incrementing number to each sequence. Also, where would be the ideal place to implement this method if I want it to run every time a new sequence is created, deleted or a sequence is updating the start field. I've been thinking about the save() and delete() method, however I dont wish to update when only other fields in the sequence is updated.

This is my sequence model

class Sequence(models.Model):

number = models.PositiveIntegerField(
    verbose_name='sequence number',
    help_text='auto incrementing sequence number',
)
schedule = models.ForeignKey(
    to=Schedule,
    verbose_name='schedule',
    on_delete=models.CASCADE,
    related_name='sequences',
    help_text='schedule primary key',
)
start = models.DateTimeField(
    verbose_name='start date',
    help_text='sequence starting datetime',
)
end = models.DateTimeField(
    verbose_name='end date',
    help_text='sequence ending datetime',
)


django

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Python Django Tutorial | Django Course

🔥Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

django-allauth Django REST Framework |teratail

Djangoアプリを、当初は Django REST Framework (DRF) を使わずに作成しました。(認証パッケージは、 django-allauthを使用)アプリリリース後に、DRFも追加で導入して、DRFで作成したAPIでのデ

Django REST Framework Course for Beginners

In this article we are going to talk about Django REST Framework Course for Beginners, also for more information you can check the complete video for th

Хранение изображений с помощью Django/Django REST

Проблема Мне в ходе разработки часто приходится работать с моделями, в которых должны быть изображения. Для удобной организации я использую древовидную структуру...

How to Integrate Django to any Javascript Front End // Django to React // Django to Angular

Learn the basic technique to Integrate Django to any Javascript Front End // Django to React // Django to Angular