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',
)


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

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 &...

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

Django

Well i used django ... i want to know after completing all the coding stuff, can i make all the codes online ?