Guest User

Untitled

a guest
Apr 6th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. class CreateView(View):
  2.     def get(self, request):
  3.         if request.user.is_authenticated and request.user.is_staff:
  4.             form = EarthCreateForm()
  5.             return render(request, 'actions/register_new_earth.html', {'form': form})
  6.         else:
  7.             return TemplateResponse(request, 'errors/401.html', status=401)
  8.  
  9.     def post(self, request):
  10.         if request.user.is_authenticated and request.user.is_staff:
  11.             form = CreateForm(request.POST)
  12.             if form.is_valid():
  13.                 cd = form.cleaned_data
  14.                 print(cd['image'])
  15.                 Earth.objects.create(
  16.                     owner=cd['owner'], year=cd['year'], cadastral_number=cd['cadastral_number'], area=cd['area'], total=cd['total'],
  17.                     price=cd['price'], notes=cd['notes'], image=cd['image'], privilege=cd['privilege'], city=cd['city'],
  18.                     property=cd['property']
  19.                 )
  20.             return redirect('earth_create_url')
  21.  
  22.         else:
  23.             return TemplateResponse(request, 'errors/401.html', status=401)
Advertisement
Add Comment
Please, Sign In to add comment