Django Admin change_form.html에 버튼 추가 및 저장시 custom 작업 수행
2021. 2. 12. 15:45ㆍ파이썬/Django
{% block submit_buttons_bottom %}
{{ block.super }}
<div class="submit-row">
<input type="submit" value="Save & Go to Boxes" name="_gotoTrainedBoxes">
<input type="submit" value="Save(include Image) & Go to Boxes" name="_gotoTrainedBoxes(include Image)">
</div>
{% endblock %}
def response_change(self, request, obj):
if "_gotoTrainedBoxes" in request.POST or "_gotoTrainedBoxes(include Image)" in request.POST :
if "_gotoTrainedBoxes(include Image)" in request.POST :
Trained_Image.createImageData(obj)
opts = self.model._meta
msg = format_html('The Trained_Image “{}” was changed successfully.', obj.id)
self.message_user(request, msg, messages.SUCCESS)
redirect_url = reverse('admin:%s_%s_changelist' %
(opts.app_label, 'trained_box'),
#args=(obj.id,),
current_app=self.admin_site.name)
#redirect_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, redirect_url)
return HttpResponseRedirect(redirect_url)
return super(Trained_ImageAdmin, self).response_change(request, obj)
'파이썬 > Django' 카테고리의 다른 글
Django PostgreSQL 연동시 에러 (0) | 2021.02.19 |
---|---|
Django filter 특징 (0) | 2021.02.17 |
Django Admin list_display에 custom link 추가 (0) | 2021.02.11 |
Django DB에 이미지 저장 및 가져오기 (0) | 2021.02.11 |
tile cannot extend outside image (0) | 2021.02.11 |