拍爱

group_photo_utils.py 782B

123456789101112131415161718192021222324252627
  1. # -*- coding: utf-8 -*-
  2. import itertools
  3. from group.models import GroupPhotoInfo
  4. def get_current_photos(group_id, user_id, current_id):
  5. # 获取从 current_id 到 now 的群组照片列表
  6. group_photos = GroupPhotoInfo.objects.filter(
  7. group_id=group_id,
  8. status=True,
  9. pk__gt=current_id,
  10. ).order_by(
  11. '-session_id',
  12. '-pk'
  13. )
  14. # 最新照片
  15. latest_photo = group_photos.first()
  16. # 照片按照 session_id 分组
  17. group_photos = map(lambda x: {'session_id': x[0], 'photos': [y.photo_info(user_id) for y in x[1]]},
  18. itertools.groupby(group_photos, lambda x: x.session_id))
  19. return {
  20. 'current_id': latest_photo and latest_photo.pk or current_id,
  21. 'photos': group_photos,
  22. }