示例#1
0
 def source_addfield_view(self,
                          request,
                          contenttype_id,
                          object_id,
                          fieldname,
                          sourcetype,
                          extra_context=None):
     info = self.model._meta.app_label, self.model._meta.model_name
     form_conf = {
         "form_class": TimelineForm,
         "form_fields": ['date_begin', 'date_end']
     }
     form = get_form_model(self.model.timeline_model, **form_conf)
     opts = self.model._meta
     to_field = request.POST.get(TO_FIELD_VAR,
                                 request.GET.get(TO_FIELD_VAR))
     obj = self.get_object_by_contenttype(request, contenttype_id,
                                          unquote(object_id), to_field)
     if request.POST:
         form = form(obj, fieldname, request.user, request.POST)
         if form.is_valid():
             return redirect('admin:%s_%s_timeline' % info,
                             object_id=object_id)
     else:
         form = form(obj, fieldname, request.user)
     context = {
         **self.admin_site.each_context(request), 'sourcetype': sourcetype,
         'form': form,
         'fieldname': fieldname,
         'object_name': str(opts.verbose_name),
         'object': obj,
         'fake': obj.source_model(),
         'opts': opts,
         'app_label': opts.app_label,
         'media': self.media
     }
     return TemplateResponse(request, 'admin/source_addfield.html', context)
示例#2
0
 def get_country_form(self):
     return get_form_model(self.country_model,
                           form_class=CompanyAddByCountry,
                           form_fields=self.country_fields)