Skip to content

Instantly share code, notes, and snippets.

View karthikbgl's full-sized avatar

Karthik Ravindra karthikbgl

  • New York, NY
View GitHub Profile
@karthikbgl
karthikbgl / save_as_new.py
Last active August 29, 2015 14:04
Django ModelAdmin "Save as New"
class MyModelAdminForm(forms.ModelForm):
'''
To add the option 'Save as New', by default does not work for reverse
ManyToMany/ForeignKey fields. In other words, does not copy over the
reverse attributes. A simple workaround to make this happen is:
update the cleaned_data and returning it in the context.
Something like this:
'''
def clean(self, *args, **kwargs):
cd = self.cleaned_data