Advertisement
Guest User

views.py

a guest
Mar 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. @method_decorator(login_required, name='dispatch')
  2. class ImmatriculationCreate(CreateView):
  3.     model = Immatriculation
  4.     template_name = 'vol/immatriculation_add.html'
  5.     fields = ['immatriculation',
  6.               'type_avion']
  7.     success_url = '/immatriculation_add/list'
  8.     # template_name_suffix = '_add'
  9.  
  10.     def get_context_data(self, **kwargs):
  11.         context = super(ImmatriculationCreate, self).get_context_data(**kwargs)
  12.         data = Immatriculation.objects.all()
  13.         context['data'] = data
  14.         return context
  15.  
  16.     def form_valid(self, form):
  17.         form.instance.user_id = self.request.user
  18.         return super(ImmatriculationCreate, self).form_valid(form)
  19.  
  20.     def dispatch(self, *args, **kwargs):
  21.         return super().dispatch(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement