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
Post a Comment