Added method to check for self-referential sortable foreign keys.
parent
d332563e27
commit
612c4f8031
|
|
@ -1,4 +1,4 @@
|
||||||
from .models import Sortable
|
from .models import Sortable, SortableForeignKey
|
||||||
|
|
||||||
|
|
||||||
def get_is_sortable(objects):
|
def get_is_sortable(objects):
|
||||||
|
|
@ -9,9 +9,22 @@ def get_is_sortable(objects):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def is_self_referential(cls):
|
||||||
|
cls_type = type(cls)
|
||||||
|
sortable_subclass = issubclass(cls_type, Sortable)
|
||||||
|
sortable_foreign_key_subclass = issubclass(cls_type, SortableForeignKey)
|
||||||
|
if sortable_foreign_key_subclass and not sortable_subclass:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def check_model_is_sortable(cls):
|
def check_model_is_sortable(cls):
|
||||||
if cls:
|
if cls:
|
||||||
if issubclass(type(cls), Sortable):
|
if is_self_referential(cls):
|
||||||
if cls.objects.count() > 1:
|
objects = cls.model.objects
|
||||||
return True
|
else:
|
||||||
|
objects = cls.objects
|
||||||
|
|
||||||
|
if objects.count() > 1:
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue