From 3acd88e8c4715ed4e9e98fa5f916177838472b17 Mon Sep 17 00:00:00 2001 From: Brandon Taylor Date: Fri, 24 Oct 2014 20:28:36 -0400 Subject: [PATCH] Added utility function to check if a model defined as a sortable foreign key inherits from Sortable and if there are more than one objects for that model. --- adminsortable/utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/adminsortable/utils.py b/adminsortable/utils.py index e2948cf..c858f88 100644 --- a/adminsortable/utils.py +++ b/adminsortable/utils.py @@ -1,5 +1,17 @@ +from .models import Sortable + + def get_is_sortable(objects): if objects: - if objects.count() > 1: - return True + if issubclass(type(objects[0]), Sortable): + if objects.count() > 1: + return True + return False + + +def check_model_is_sortable(cls): + if cls: + if issubclass(type(cls), Sortable): + if cls.objects.count() > 1: + return True return False