{"action":"created","issue":{"url":"https://api.github.com/repos/AndrewIngram/django-extra-views/issues/107","labels_url":"https://api.github.com/repos/AndrewIngram/django-extra-views/issues/107/labels{/name}","comments_url":"https://api.github.com/repos/AndrewIngram/django-extra-views/issues/107/comments","events_url":"https://api.github.com/repos/AndrewIngram/django-extra-views/issues/107/events","html_url":"https://github.com/AndrewIngram/django-extra-views/issues/107","id":102195956,"number":107,"title":"Save request.user to an django extra view","user":{"login":"bobhsr","id":1159196,"avatar_url":"https://avatars.githubusercontent.com/u/1159196?v=3","gravatar_id":"","url":"https://api.github.com/users/bobhsr","html_url":"https://github.com/bobhsr","followers_url":"https://api.github.com/users/bobhsr/followers","following_url":"https://api.github.com/users/bobhsr/following{/other_user}","gists_url":"https://api.github.com/users/bobhsr/gists{/gist_id}","starred_url":"https://api.github.com/users/bobhsr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bobhsr/subscriptions","organizations_url":"https://api.github.com/users/bobhsr/orgs","repos_url":"https://api.github.com/users/bobhsr/repos","events_url":"https://api.github.com/users/bobhsr/events{/privacy}","received_events_url":"https://api.github.com/users/bobhsr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-20T17:57:52Z","updated_at":"2015-09-21T14:31:47Z","closed_at":null,"body":"The example is from Django-Extra-Views. Seems to be working as the example states.\r\n\r\nThrows errors if added request.user\r\n\r\nhttps://django-extra-views.readthedocs.org/en/latest/views.html\r\n\r\n\r\n\tclass OrderCreateView(CreateWithInlinesView):\r\n\t    model = Order\r\n\t    inlines = [ItemsInline, TagsInline]\r\n\r\n\t    def get_success_url(self):\r\n\t        return self.object.get_absolute_url()\r\n\r\n\r\n\r\nThe following have been tried. They do not work.\r\n\r\n\r\n\tdef form_valid(self, form):\r\n        # self.object = form.save()\r\n        form.instance.owner = self.request.user\r\n        form.save()\r\n        return super(OrderCreateView, self).form_valid(form)\r\n\r\n    throws error:\r\n     IntegrityError at /add/\r\n\t null value in column \"owner_id\" violates not-null constraint\r\n\r\n\r\nAlso tried adding it form.save\r\n\r\n\tdef save(self,  commit=True):\r\n        instance = super(OrderCreateView, self).save(commit=False)\r\n        instance.owner = self.request.user\r\n        instance.save()\r\n\r\n\r\n    throws \r\n    'OrderForm' object has no attribute 'request'"},"comment":{"url":"https://api.github.com/repos/AndrewIngram/django-extra-views/issues/comments/141999750","html_url":"https://github.com/AndrewIngram/django-extra-views/issues/107#issuecomment-141999750","issue_url":"https://api.github.com/repos/AndrewIngram/django-extra-views/issues/107","id":141999750,"user":{"login":"berkerpeksag","id":26338,"avatar_url":"https://avatars.githubusercontent.com/u/26338?v=3","gravatar_id":"","url":"https://api.github.com/users/berkerpeksag","html_url":"https://github.com/berkerpeksag","followers_url":"https://api.github.com/users/berkerpeksag/followers","following_url":"https://api.github.com/users/berkerpeksag/following{/other_user}","gists_url":"https://api.github.com/users/berkerpeksag/gists{/gist_id}","starred_url":"https://api.github.com/users/berkerpeksag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/berkerpeksag/subscriptions","organizations_url":"https://api.github.com/users/berkerpeksag/orgs","repos_url":"https://api.github.com/users/berkerpeksag/repos","events_url":"https://api.github.com/users/berkerpeksag/events{/privacy}","received_events_url":"https://api.github.com/users/berkerpeksag/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T14:31:47Z","updated_at":"2015-09-21T14:31:47Z","body":"Hey @bobhsr, I've solved the same problem with following code:\r\n\r\n```py\r\nclass DocumentFormSetCreateView(CreateWithInlinesView):\r\n    # your normal settings\r\n\r\n    def forms_valid(self, form, inlines):\r\n        self.object = form.save()\r\n        revision = inlines[0].save(commit=False)[0]  # we just have one item\r\n        revision.creator = self.request.user\r\n        revision.save()\r\n        return HttpResponseRedirect(self.get_success_url())\r\n```\r\n\r\nSo, you'll need to override the `forms_valid`method instead of `form_valid`."}}