0
ユーザーがチームの設定の一部を更新できるようにしていますが、正しく動作しないようです。Django - モデルフォームでモデルを更新できません。strエラーが発生しました
Views.py
@login_required
def teamsettings_general(request, team_pk):
logged_in_user = get_object_or_404(User, pk=request.user.pk)
requested_team = get_object_or_404(Team, pk=team_pk)
if request.method == 'POST':
for member in requested_team.teammembership_set.all().order_by('-leader'):
if member.user.pk == request.user.pk and member.leader:
form = TeamSettings_GeneralForm(request.POST, instance=team_pk)
if form.is_valid():
form.save()
messages.success(request, "The team has been updated!")
return redirect('teamsettings_general', team_pk=team_pk)
for member in requested_team.teammembership_set.all().order_by('-leader'):
if member.user.pk == request.user.pk and member.leader:
feedback = FeedbackSupportForm()
form = TeamSettings_GeneralForm(instance=team_pk)
context = {
'requested_team': requested_team,
'feedback': feedback,
'form' : form,
'logged_in_user': logged_in_user,
}
return render(request, 'team/settings.html', context)
break
else: return redirect('team', team_pk)
と
class TeamSettings_GeneralForm(forms.ModelForm):
class Meta:
model = Team
fields = ('name', 'accepts_applications',)
私form.py今、私はちょうどそれが名前とaccepts_applications
'str' object has no attribute '_meta'
form = TeamSettings_GeneralForm(request.POST, instance=team_pk)
if form.is_valid():
form.save()
messages.success(request, "The team has been updated!")
return redirect('teamsettings_general', team_pk=team_pk)
logged_in_user = get_object_or_404(User, pk=request.user.pk)
requested_team = get_object_or_404(Team, pk=team_pk)
form = TeamSettings_GeneralForm(instance=team_pk) ...
for member in requested_team.teammembership_set.all().order_by('-leader'):
if member.user.pk == request.user.pk and member.leader:
feedback = FeedbackSupportForm()
context = {
'requested_team': requested_team,
'feedback': feedback,
にadbanvce