fix to optimize querysets (#108)

This commit is contained in:
kdelinx 2018-06-23 21:38:59 +07:00 committed by Martin Mahner
parent 5702672ab4
commit 7aed1b5ce5

View file

@ -85,7 +85,7 @@ class SnippetDetailView(SnippetView, DetailView):
# Increase the view count of the snippet # Increase the view count of the snippet
snippet.view_count += 1 snippet.view_count += 1
snippet.save() snippet.save(update_fields=['view_count'])
return super(SnippetDetailView, self).get(request, *args, **kwargs) return super(SnippetDetailView, self).get(request, *args, **kwargs)
@ -251,21 +251,20 @@ class APIView(View):
expires = datetime.datetime.now() + datetime.timedelta(seconds=60 * 60 * 24) expires = datetime.datetime.now() + datetime.timedelta(seconds=60 * 60 * 24)
expire_type = Snippet.EXPIRE_TIME expire_type = Snippet.EXPIRE_TIME
s = Snippet.objects.create( snippet = Snippet.objects.create(
content=content, content=content,
lexer=lexer, lexer=lexer,
expires=expires, expires=expires,
expire_type=expire_type, expire_type=expire_type,
) )
s.save()
# Custom formatter for the API response # Custom formatter for the API response
formatter = getattr(self, '_format_{0}'.format(response_format), None) formatter = getattr(self, '_format_{0}'.format(response_format), None)
if callable(formatter): if callable(formatter):
return HttpResponse(formatter(s)) return HttpResponse(formatter(snippet))
# Otherwise use the default one. # Otherwise use the default one.
return HttpResponse(self._format_default(s)) return HttpResponse(self._format_default(snippet))
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------