If you want to set the status field on the model after you save the form, you can do something like this: msg_instance = form.save(commit=False) msg_instance.status = 'F' msg_instance.save() # don't forget the save, because the form didn't # save the model
On Wed, 2009-10-07 at 06:14 -0700, valler wrote: > Hello. > > I can't understand how I can add some extra fields on form saving. > > Here is a simple example: > > class Msg(models.Model): > title = models.CharField(max_length=30) > message = models.CharField(max_length=100) > status = models.CharrField(max_length=1,null=True,blank=True) > > class MsgForm(ModelForm): > class Meta: > model = Msg > exclude = ('status') ## I don't want users to see it in html form > ## > > ... > status = 'F' ## for example > if request.method == 'POST': > form = msgForm(request.POST) > if form.is_valid: > form.save() ???? > > How can i set status here? If i set form = msgForm(request.POST, > initial={status:'F'}) - this does nothing. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---