django - PostgreSQL - check for empty list -
i've written application in django , tested using sqlite. in production want use postgresql , there's problem, because calling:
empty_list = [] foo.objects.exclude(pk__in=empty_list).delete()
raises programmingerror (bad query - postgres doesn't accept in queries empty in ()
)
i don't want rewrite code , wrap exclude
s , filter
s in method checks empty list. don't want write thousand of if
s or modify django code. there elegant solution solve this?
ok, found this: http://www.tryolabs.com/blog/2013/07/05/run-time-method-patching-python/
it's simple, write sth this:
from django.db.models import queryset def new_exclude(self, *args, **kwargs): kw = dict() key, value in kwargs.items(): if is_not_empty_list(value) , is_not_empty_queryset(value): #other checks? kw[key] = value if len(kw): return old_exclude(self, *args, **kw) else: return self old_exclude = queryset.exclude queryset.exclude = new_exclude
but don't solution, won't accept , i'm waiting better one.
Comments
Post a Comment