1 2 3 4 5 6 7 | from django.db.models import AutoField
def copy_model_instance(obj):
initial = dict([(f.name, getattr(obj, f.name))
for f in obj._meta.fields
if not isinstance(f, AutoField) and\
not f in obj._meta.parents.values()])
return obj.__class__(**initial)
|
More like this
- Per-Instance On-Model M2M Caching by bryanhelmig 1 year, 6 months ago
- ModelForm Class saving m2m by ckarrie2 4 months ago
- Clone model mixin by zakj 3 years, 1 month ago
- How to connect m2m_changed sent by specific senders for symmetrical m2ms by ilikefm 3 months, 1 week ago
- load m2m fields objects by dirol 1 year, 8 months ago
Comments