stash
This commit is contained in:
parent
b109e5995e
commit
fda7b80ca4
1 changed files with 7 additions and 4 deletions
|
@ -26,13 +26,16 @@ class ContainerViewSet(viewsets.ModelViewSet):
|
|||
class ItemViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = ItemSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Item.objects.all()
|
||||
def prefetch_queryset(self, queryset):
|
||||
serializer = self.get_serializer_class()
|
||||
if hasattr(serializer, 'Meta') and hasattr(serializer.Meta, 'prefetch_related_fields'):
|
||||
queryset = queryset.prefetch_related(*serializer.Meta.prefetch_related_fields)
|
||||
return queryset
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Item.objects.all()
|
||||
return self.prefetch_queryset(queryset)
|
||||
|
||||
|
||||
def filter_items(items, query):
|
||||
query_tokens = query.split(' ')
|
||||
|
@ -69,7 +72,7 @@ def item(request, event_slug):
|
|||
if request.method == 'GET':
|
||||
if not request.user.has_event_perm(event, 'view_item'):
|
||||
return Response(status=403)
|
||||
return Response(ItemSerializer(vs.get_queryset().filter(event=event), many=True).data)
|
||||
return Response(ItemSerializer(vs.prefetch_queryset(Item.objects.filter(event=event)), many=True).data)
|
||||
elif request.method == 'POST':
|
||||
if not request.user.has_event_perm(event, 'add_item'):
|
||||
return Response(status=403)
|
||||
|
@ -108,7 +111,7 @@ def add_comment(request, event_slug, id):
|
|||
def item_by_id(request, event_slug, id):
|
||||
try:
|
||||
event = Event.objects.get(slug=event_slug)
|
||||
item = ItemViewSet().get_queryset().get(event=event, id=id)
|
||||
item = Item.objects.get(event=event, id=id)
|
||||
if request.method == 'GET':
|
||||
if not request.user.has_event_perm(event, 'view_item'):
|
||||
return Response(status=403)
|
||||
|
|
Loading…
Add table
Reference in a new issue