python - Pass Variable to Django Admin Form -
i have add form calibrationcertificates in django admin site. if link non-admin template, instrument_detail.html, possible pass context information default value add form.
that is, choice in add form instrument certificate for. link associated instrument, there way pass value, such add certificate form default instrument user came from?
my modeladmin follows:
class certificateadmin(admin.modeladmin): exclude = ('issued_by', 'expires',) def save_model(self, request, obj, form, change): obj.issued_by = request.user obj.expires= datetime.date.today() + datetime.timedelta(days=obj.instrument.kind.duration) obj.save()
not sure if understand question correctly think want:
def add_view(self, request, form_url='', extra_context=none): extra_context = extra_context or {} extra_context['my_extra_content'] = self.something return super(mymodeladmin, self).add_view(request, form_url, extra_context=extra_context)
Comments
Post a Comment