Thursday, June 13, 2013

Re: Class Based CreateView with foreign key question

I should also clarify just in case anyone else runs into the same problem in the future:

My form_valid() was not working correctly because I had my form definition excluding a (required) field so it would NEVER be able to save my model under any circumstance.

    def form_valid(self, form):
        theFile = form.save(commit=False)
        theFile.evidence = self.case
        theFile.save()
        response = ...
        return response


This is the same pattern I've done many times in the past, I just wasn't able to wrap my head around it with generic CBV. It's probably not ideal that I don't call super() in there but I don't think there's an effective way to handle it that way.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate