Added to set the current user of the data model if the model is our BaseModel in the fill_model_from_form() method in FormView in the Mia core application.

This commit is contained in:
依瑪貓 2020-08-18 10:01:45 +08:00
parent a6fc865b3e
commit 321165a50f

View File

@ -32,6 +32,7 @@ from django.views.generic import DeleteView as CoreDeleteView
from django.views.generic.base import View
from . import stored_post, utils
from .models import BaseModel
from .utils import UrlBuilder
@ -126,6 +127,8 @@ class FormView(View):
"""Fills in the data model from the form."""
for name in form.fields:
setattr(obj, name, form[name].value())
if isinstance(obj, BaseModel):
obj.current_user = self.request.user
def form_invalid(self, form: forms.Form) -> HttpResponseRedirect:
"""Handles the action when the POST form is invalid."""