0👍
✅
I hate always being the one that responds its own questions, but I solved using this:
class Reservation(models.Model):
# ...
def relative_id(self):
return self.id - Reservation.objects.filter(id__lt=self.id).filter(~Q(event=self.event)).all().count()
Assuming records from reservations are never deleted, we can safely assume the “relative id” is the incremental id – (count of reservations before this one not belonging to same event).
I’m thinking of any drawbacks, but I didn’t find any.
0👍
Filtering using Reservation.objects.filter(event_id = some_event_id)
should suffice. This will give you a QuerySet that should have the same ordering each time. Or am I missing something in your question?
- [Django]-How much dog food should one eat? – Internal and External RestAPI & Oauth2
- [Django]-What's your favorite way to test the javascript in your djangoapp?
- [Django]-How to test APIView in Django, Django Rest Framework
- [Django]-Force re-collectstatic with django static?
- [Django]-How to use ListSerializer with a ModelSerializer?
Source:stackexchange.com