python - Django Forms: Avoid DB hit during import -


i have legacy django code:

class fooform(forms.form):     defaults={         'foo': foo.objects.get(id='...')          } 

foo.objects.get() not lazy. means db connected during importing python file.

this makes trouble in several places.

how refactor this? there lazy version of foo.objects.get()?

it sounds want hit database when instantiating form. i'd overriding constructor:

class fooform(forms.form):     def __init__(*args, **kwargs):         super(fooform, self).__init__(*args, **kwargs)          self.defaults = {             'foo': foo.objects.get(id='...')          } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -