Created
May 28, 2012 01:41
-
-
Save rasca/2816729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# New FormSet Mixin | |
def construct_formsets(self, **kwargs): | |
prefixes = {} | |
object = getattr(self, 'object', None) | |
for FormSet, inline in zip(self.admin_opts.get_formsets( | |
self.request, object), self.inline_instances): | |
prefix = FormSet.get_default_prefix() | |
prefixes[prefix] = prefixes.get(prefix, 0) + 1 | |
if prefixes[prefix] != 1 or not prefix: | |
prefix = "%s-%s" % (prefix, prefixes[prefix]) | |
formset_kwargs = { | |
'prefix' :prefix, | |
'queryset': inline.queryset(self.request) | |
'instance': 'object' or self.model() | |
} | |
if self.request.method in ('POST', 'PUT'): | |
formset_kwargs.update({ | |
'data': self.request.POST, | |
'files': self.request.FILES, | |
}) | |
formset_kwargs.update(kwargs) | |
self.formsets.append(FormSet(**formset_kwargs)) | |
# Call it like: | |
construct_formsets(save_as_new="_saveasnew" in self.request.POST) | |
# or | |
construct_formsets() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment