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 excludes , filters in method checks empty list. don't want write thousand of ifs 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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -