1👍
✅
Actually, your solution is almost ok. There are few advices:
- Don’t
deepcopy
queryset, it’s cloned when you slice it anyway. - Slicing is inefficient from database perspective (large offset in a sql), it means database needs to prepare many rows and then pass you only few.
- Slicing is also unsafe if anything can be added or deleted from table in between.
You can adapt this thing to your case. Just use item_id
instead of pk
. It uses condition instead of offset so it’s much more efficient.
👤Suor
Source:stackexchange.com