Skip to content

Commit

Permalink
balls: handle large deletions
Browse files Browse the repository at this point in the history
  • Loading branch information
laggron42 committed Jan 17, 2025
1 parent 77bc02b commit 1a373a7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion admin_panel/bd_models/admin/ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.forms import Textarea
from django.utils.safestring import mark_safe

from ..models import Ball, Economy, Regime
from ..models import Ball, BallInstance, Economy, Regime, TradeObject
from ..utils import transform_media

if TYPE_CHECKING:
Expand Down Expand Up @@ -133,3 +133,16 @@ def formfield_for_dbfield(
if db_field.name == "capacity_description":
kwargs["widget"] = Textarea()
return super().formfield_for_dbfield(db_field, request, **kwargs) # type: ignore

def get_deleted_objects(
self, objs: "list[Ball]", request: "HttpRequest"
) -> tuple[list[str], dict[str, int], set[Any], list[Any]]:
instances = BallInstance.objects.filter(ball_id__in=set(x.pk for x in objs))
if len(instances) < 500:
return super().get_deleted_objects(objs, request) # type: ignore
model_count = {
"balls": len(objs),
"ball instances": len(instances),
"trade objects": TradeObject.objects.filter(ballinstance_id__in=instances).count(),
}
return ["Too long to display"], model_count, set(), []

0 comments on commit 1a373a7

Please sign in to comment.