Hi, What is the correct way to set a field value in the form_valid method of a CreateView? Note the field is not on the form and I don't want to use a default value in the model. For example:
def get_state(type_desc, state_desc): type = Type.objects.get(description=type_desc) return State.objects.get(state_type=type, description=state_desc) class CreateFlow(CreateView): model = Flow fields = [] template_name = 'create_flow.html' def form_valid(self, form): state = get_state("test type", "test state") # How to set the state field here on the Flow table? result = super(CreateFlow, self).form_valid(form) log = Log(user=self.request.user, flow=self.object, state=state) log.save() return result This gives an error because the state field on the Flow table has not been given a value: Request Method: POST Request URL: http://127.0.0.1:8000/create/ Django Version: 1.7 Exception Type: IntegrityError Exception Value: null value in column "state_id" violates not-null constraint Thanks. -- 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+unsubscr...@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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c164b88a-1da1-449a-a409-c6a47aa58b4c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.