1👍
✅
A ModelAdmin
has no .form_valid(…)
method [Django-doc], this is for class-based views (CBVs) that inherit from a FormMixin
[Django-doc]. The ModelAdmin
will call the .save_model(…)
method [Django-doc], so you should implement the logic in that method:
class MyModelAdmin(admin.ModelAdmin):
# …
def save_model(self, request, obj, form, change):
obj.author = request.user
super().save_model(request, obj, form)
bid = round(float(form.cleaned_data['starting_bid']), 2)
Bid.objects.create(
bid_value = bid,
bidder = request.user,
item=obj
)
Source:stackexchange.com