I have a table for storing reservations for specific events; The corresponding part:
class Reservation(models.Model):
Now I want to get the sequential identifier of this reservation relative to the reservation for the same event.
Disclaimer: Of course, we assume that reservations are never deleted or their relative position may change.
Example:
+----+-------+------------+--------+ | ID | Event | First name | Rel.ID | +----+-------+------------+--------+ | 1 | 1 | AAA | 1 | | 2 | 1 | BBB | 2 | | 3 | 2 | CCC | 1 | | 4 | 2 | DDD | 2 | | 5 | 1 | EEE | 3 | | 6 | 3 | FFF | 1 | | 7 | 1 | GGG | 4 | | 8 | 1 | HHH | 5 | +----+-------+------------+--------+
The last column is the "Relative identifier", that is, a sequential number without spaces for all reservations of the same event.
Now, what is the best way to do this without having to manually calculate the relative identifier for each import (I don't like this)? I use postgresql as the base database, but I would prefer to stick with the django abstraction layer to preserve this migration (i.e., No database-specific solutions like triggers, etc.).
source share