コード例 #1
0
 def get_object(self, queryset=None):
     pk = self.kwargs.get('pk', -1)
     model_str = self.kwargs.get('model_str', None)
     if model_str in URL_DICT.keys():
         obj = get_object_or_404(URL_DICT[model_str], pk=pk)
     else:
         obj = None
     return obj
コード例 #2
0
    def get_context_data(self, *args, **kwargs):
        self.context = super().get_context_data(*args, **kwargs)
        #self.context['referer'] = self.request.META.get('HTTP_REFERER', '/')

        model_str = self.kwargs.get('model_str', None)
        if model_str in URL_DICT.keys():
            model = URL_DICT[model_str]
            self.context['col_names'] = model.get_field_names_gen()
            self.context['col_m2m'] = model.get_m2m_field_names_gen()
            self.context['model_name'] = model._meta.verbose_name
            self.context['url_pref'] = add_slash(model.Other.url)
        return self.context
コード例 #3
0
 def get_form_class(self):
     self.model_str = self.kwargs.get('model_str', None)
     if self.model_str in URL_DICT.keys():
         self.model = URL_DICT[self.model_str]
         self.success_url = reverse_lazy(f'mainapp:{self.model_str}_list')
         return FORM_DICT[self.model_str]