This repository was archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
45 lines (31 loc) · 1.29 KB
/
views.py
File metadata and controls
45 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Create your views here.
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import ListView, CreateView, UpdateView
from aplicatie1.models import Locations
class LocationsView(LoginRequiredMixin, ListView):
model = Locations
template_name = 'aplicatie1/locations_index.html'
paginate_by = 5
class CreateLocationView(LoginRequiredMixin, CreateView):
model = Locations
fields = ['city', 'country']
template_name = 'aplicatie1/locations_form.html'
def get_success_url(self):
return reverse('locations:lista_locatii')
class UpdateLocationView(LoginRequiredMixin, UpdateView):
model = Locations
fields = ['city', 'country']
template_name = 'aplicatie1/locations_form.html'
def get_success_url(self):
return reverse('locations:lista_locatii')
@login_required
def delete_location(request, pk):
Locations.objects.filter(id=pk).update(active=0)
return redirect('locations:lista_locatii')
@login_required
def activate_location(request, pk):
Locations.objects.filter(id=pk).update(active=1)
return redirect('locations:lista_locatii')