def __init__(self, cache_for_form_optimization=None, *args, **kwargs): # The cache_for_form_optimization is an object that is # optionally created by the request that calls # BulkEditForm. One difficulty with BulkEditForms is that the # forms generate similar data over and over again; we can # avoid some database hits by running some queries just once # (at BulkEditForm instantiation time), rather than once per # sub-form. # # However, it is unsafe to cache data in the BulkEditForm # class because that persists for as long as the Python # process does (meaning that subsequent requests will use the # same cache). EditVideoForm.__init__(self, *args, **kwargs) # We have to initialize tags manually because the model form # (django.forms.models.model_to_dict) only collects fields and # relations, and not descriptors like Video.tags self.initial['tags'] = utils.edit_string_for_tags(self.instance.tags) # cache the querysets so that we don't hit the DB for each form cache_for_form_optimization = self.fill_cache(cache_for_form_optimization) self.fields['categories'].queryset = cache_for_form_optimization[ 'categories_qs'] self.fields['authors'].queryset = cache_for_form_optimization[ 'authors_qs']
def __init__(self, cache_for_form_optimization=None, *args, **kwargs): # The cache_for_form_optimization is an object that is # optionally created by the request that calls # BulkEditForm. One difficulty with BulkEditForms is that the # forms generate similar data over and over again; we can # avoid some database hits by running some queries just once # (at BulkEditForm instantiation time), rather than once per # sub-form. # # However, it is unsafe to cache data in the BulkEditForm # class because that persists for as long as the Python # process does (meaning that subsequent requests will use the # same cache). EditVideoForm.__init__(self, *args, **kwargs) # We have to initialize tags manually because the model form # (django.forms.models.model_to_dict) only collects fields and # relations, and not descriptors like Video.tags self.initial['tags'] = utils.edit_string_for_tags(self.instance.tags) # cache the querysets so that we don't hit the DB for each form cache_for_form_optimization = self.fill_cache( cache_for_form_optimization) self.fields['categories'].queryset = cache_for_form_optimization[ 'categories_qs'] self.fields['authors'].queryset = cache_for_form_optimization[ 'authors_qs']
def __init__(self, *args, **kwargs): forms.ModelForm.__init__(self, *args, **kwargs) self.initial['tags'] = edit_string_for_tags(self.instance.tags)