39 lines
949 B
Python
39 lines
949 B
Python
from django import forms
|
|
from django.urls import reverse_lazy
|
|
from django.views.generic import ListView, UpdateView
|
|
|
|
from dronken.models import City, Association
|
|
|
|
|
|
class CityList(ListView):
|
|
template_name = 'cities.html'
|
|
model = City
|
|
|
|
|
|
class AssociationList(ListView):
|
|
template_name = 'associations.html'
|
|
model = Association
|
|
|
|
def get_queryset(self):
|
|
c = City.objects.get(slug=self.kwargs['city'])
|
|
return Association.objects.filter(city=c)
|
|
|
|
|
|
class DrunkUpdateForm(forms.ModelForm):
|
|
state = forms.CharField(
|
|
widget=forms.Select(choices=Association.STATES),
|
|
)
|
|
|
|
class Meta:
|
|
model = Association
|
|
fields = ['state']
|
|
|
|
|
|
class AssociationDetail(UpdateView):
|
|
template_name = 'association.html'
|
|
model = Association
|
|
form_class = DrunkUpdateForm
|
|
|
|
def get_success_url(self):
|
|
return reverse_lazy('dronken:association_list', kwargs={'city': self.get_object().city.slug})
|