* Query optimization
* Cleanup
This commit is contained in:
parent
cf5ab13fc8
commit
dab4fbd0a4
|
|
@ -15,6 +15,9 @@ class UserAdmin(admin.ModelAdmin):
|
|||
class BonusProgramTransactionAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'type', 'user', 'date', 'amount', 'comment', 'order', 'was_cancelled')
|
||||
|
||||
def get_queryset(self, request):
|
||||
return BonusProgramTransaction.objects.with_base_related()
|
||||
|
||||
def delete_queryset(self, request, queryset):
|
||||
for obj in queryset:
|
||||
obj.cancel()
|
||||
|
|
|
|||
|
|
@ -64,9 +64,8 @@ class BonusType:
|
|||
|
||||
|
||||
class BonusProgramTransactionQuerySet(models.QuerySet):
|
||||
# TODO: optimize queries
|
||||
def with_base_related(self):
|
||||
return self.select_related('order')
|
||||
return self.select_related('order', 'user')
|
||||
|
||||
def cancel(self):
|
||||
for t in self:
|
||||
|
|
|
|||
|
|
@ -44,8 +44,5 @@ class PromoCodeAdmin(admin.ModelAdmin):
|
|||
|
||||
@admin.register(Gift)
|
||||
class GiftAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'min_price')
|
||||
|
||||
|
||||
|
||||
list_display = ('name', 'min_price', 'available_count')
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ from rest_framework import generics, permissions, mixins, status, viewsets
|
|||
from rest_framework.decorators import action
|
||||
from rest_framework.exceptions import NotFound
|
||||
from rest_framework.filters import SearchFilter
|
||||
from rest_framework.generics import get_object_or_404
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
|
@ -99,7 +98,7 @@ class ChecklistAPI(viewsets.ModelViewSet):
|
|||
obj.cancel()
|
||||
|
||||
def get_queryset(self):
|
||||
return Checklist.objects.all().with_base_related() \
|
||||
return Checklist.objects.with_base_related() \
|
||||
.annotate_bonus_used() \
|
||||
.default_ordering()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user