Fix team creation failure when City isn't defined by making City a required field
This commit is contained in:
parent
5b0104ea98
commit
8e6fc7c4da
2 changed files with 10 additions and 8 deletions
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue