diff --git a/events/forms.py b/events/forms.py index 82dd983..10b43ce 100644 --- a/events/forms.py +++ b/events/forms.py @@ -149,24 +149,26 @@ class DateTimeWidget(forms.SplitDateTimeWidget): class TeamForm(forms.ModelForm): class Meta: model = Team - fields = ['name', 'description', 'country', 'spr', 'city', 'web_url', 'tz'] + fields = ['name', 'description', 'city', 'web_url', 'tz'] widgets = { - 'country': Lookup(source='/api/country/', label='name'), - 'spr': Lookup(source='/api/spr/', label='name'), 'city': Lookup(source='/api/cities/', label='name'), } - raw_id_fields = ('country','spr','city') + raw_id_fields = ('city') + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['city'].required = True class NewTeamForm(forms.ModelForm): class Meta: model = Team fields = ['name', 'description', 'city', 'web_url', 'tz'] widgets = { - #'country': Lookup(source='/api/country/', label='name'), - #'spr': Lookup(source='/api/spr/', label='name'), 'city': Lookup(source='/api/cities/', label='name'), } raw_id_fields = ('city') + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['city'].required = True class DeleteTeamForm(forms.Form): confirm = forms.BooleanField(label="Yes, delete team", required=True) diff --git a/get_together/views/teams.py b/get_together/views/teams.py index 7082a7c..2b4edc8 100644 --- a/get_together/views/teams.py +++ b/get_together/views/teams.py @@ -46,7 +46,7 @@ def create_team(request, *args, **kwargs): return render(request, 'get_together/teams/create_team.html', context) elif request.method == 'POST': form = NewTeamForm(request.POST) - if form.is_valid: + if form.is_valid(): new_team = form.save() new_team.owner_profile = request.user.profile new_team.save() @@ -76,7 +76,7 @@ def edit_team(request, team_id): return render(request, 'get_together/teams/edit_team.html', context) elif request.method == 'POST': form = TeamForm(request.POST, instance=team) - if form.is_valid: + if form.is_valid(): new_team = form.save() new_team.owner_profile = request.user.profile new_team.save()