Hi, I hope I understood it right. You could set the field to editable=False, the rest Django will take care.
Btw, you have a typo "attachement" should be "attachment" I think. On Mar 18, 2:47 pm, Benedict Verheyen <[email protected]> wrote: > Hi, > > i have a problem when saving a form for updating. > In my model, i have a field date_created. > Now when i edit the form, i don't want that field to be editable and > thus is don't include it in the field list. > > I have specified a form where i specify the fields that i want to see on the > form. > I have left 'date_created' out of there. > In my view, i setup the form like this: > form = ActionForm(request.POST, action) > > I thought this would take care of setting the date_created field, apparantly > not. > I get an error when saving the updated form. > > IntegrityError at /management/action/edit/9/ > null value in column "date_created" violates not-null constraint > > This is the form: > > class ActionForm(forms.ModelForm): > performed_by = > forms.ModelChoiceField(queryset=User.objects.filter(is_active__exact=True, > is_staff__exact=True).order_by('first_name') ) > description = forms.CharField(widget=forms.Textarea(attrs={'cols':'90'})) > class Meta: > model = Action > fields = ('performed_by', 'description', 'public') > > The model: > class Action(models.Model): > class Meta: > verbose_name = _('Action') > verbose_name_plural = _('Actions') > db_table = 'calltracking_action' > ordering = ('date_created',) > app_label = 'management' > performed_by = models.ForeignKey(User, limit_choices_to = > {'is_staff':True}) > date_created = models.DateTimeField("Date action > performed",auto_now_add=True, blank=False) > description = models.TextField() > call = models.ForeignKey(Call) > public = models.BooleanField(default=False) > attachement = models.FileField(upload_to="/files/",blank=True) > def __unicode__(self): > return self.description[:40] > > The template only contains labels and fields for the 3 visible fields. > I have the same problem with the call field. I don't want people to be able > to change it. > > I now save the info like this in my view: > actionf=form.save(commit=False) > actionf.call = Call.objects.get(pk=action.call.id) > actionf.save() > form.save_m2m() > > What is the best solution for this problem? > Should i explicitely set the date_created in the view too? That would mean i > just need to get > it from the existing action but as i said, i thought "form = > ActionForm(request.POST, action)" > took care of that. > Or is it better to specify the fields as hiddenfields? > > Thanks -- 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.

