1👍
✅
I don’t really know what you mean about inefficiency. Databases are highly optimised, with indexes, to do things like counting. This:
MyModel.objects.count()
translates to a simple SELECT COUNT(...)
which is as efficient as it gets. You can’t simply take the highest autoincremented ID, as that takes no account of deleted records: it’s perfectly possible for there to be only a single row in the table, but for that row to have an ID in the millions or billions.
Source:stackexchange.com