3👍
✅
Something along the lines of the following should help you:
class MyModelAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
form = super(MyModelAdmin, self).get_form(request, obj, **kwargs)
latest_object = MyModel.objects.latest('created_at') # change this field to fit your model
form.base_fields['my_first_field_name'].initial = latest_object.my_first_field_name
form.base_fields['my_second_field_name'].initial = latest_object.my_second_field_name
return form
Hope it helps!
1👍
You can add the option save_as = True
inside the ModelAdmin
you want to use (here is the doc)
This will change the button ‘Save and add another’ to ‘Save as new’ only for the existent objects, or the object you’ve just created after using the button ‘Save and continue editing’.
This allow to use any created object to create a variant.
class ObjectAdmin(admin.ModelAdmin):
save_as = True
- [Django]-Model datetime field validation for fields with auto_now
- [Django]-Invoking django tests in subdirectories
Source:stackexchange.com