1๐
โ
How come, I cannot set the user in the data-dict.
A form will ignore all fields that it does not have to process. This makes the webserver more secure: here we ensure that the user can not create a MyModel
for another user.
If thus a field belongs to the excluded
attribute, or not in the fields
attribute from the Meta
class, then the form will not set the corresponding model object attribute.
You did not specify the instance
to the form:
def myView(request):
user = request.user
instance = MyModel(user=user)
data = {"link":link,"date_added":domain}
form = MyModelForm(data=data, instance=instance)
form.save()
Source:stackexchange.com