On 11/01/12 20:54, Juergen Schackmann wrote:
if is use this code, as proposed by russ:
    def form_valid(self, form):
self.object.user = ... (something meaningful.. e.g., self.request.user)
        return super(CreateCampaignView, self).form_valid(form)

i get the error 'NoneType' object has no attribute 'user'. and actually, by looking at the source code, that is exactly what is supposed to happen in a create view: self.object is set to None, as you can see in BaseCreateView

    def post(self, request, *args, **kwargs):
        self.object = None
        return super(BaseCreateView, self).post(request, *args, **kwargs)

am i the only one having this problem? any help is highly appreciated.
thanks
juergen
--
I agree that it looks like self.object is None, so you can't set self.object.user as Russ wrote.

How about the following:

    def form_valid(self, form):
        form.instance.user = request.user
        return super(CreateCampaignView, self).form_valid(form)

I haven't had a chance to test the code. I hope that it works, or at least leads you in the right direction!

Regards,
Alasdair

--
Alasdair Nicol
Developer, MEMSET

mail: [email protected]
 web: http://www.memset.com/

Memset Ltd., registration number 4504980. 25 Frederick Sanger Road, Guildford, 
Surrey, GU2 7YD, UK.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to