1👍
✅
Your error is in line request.project.save()
, request doesn’t have project attribute.
And actually you don’t need to call save()
method for project.
Because ProjectUpdateForm
is the ModelForm
and ModelForm.save()
(Django docs) method will create a new instance of the specified model or update assigned instance.
@admin_check
def update(request, name):
project = Project.objects.get(name = name)
if request.method == "POST":
pr_form = ProjectUpdateForm(request.POST,
request.FILES,
instance=project)
#if is_admin in Member == True: #need to authenticate user, access user permissions, if user has permission:
if pr_form.is_valid():
# save() returns an instance object, you can use it to manipulate your object.
instance = pr_form.save()
messages.success(request, f'This project has been updated.')
# YOUR ERROR IS ⬇️ HERE request doesn't have project attribute
# request.project.save()
# redirect with arguments
return redirect('project', name=instance.name)
...
Also your redirect must contain argument name
, because your project url required name attribute:
redirect('project', name=instance.name)
👤NKSM
Source:stackexchange.com