Whilst I appreciate that hidden fields can be less than ideal in some cases I want to set default values in a form generated from a model.
http://code.djangoproject.com/wiki/CookBookManipulatorWithHiddenFields gives some guidance but this approach appears to be deprecated in django 1.02 (and the refernced cookbook pages does not say so) What is the new way to do this pls? Thx. Paul class Note(models.Model): organisation = models.ForeignKey(Organisation) contact = models.ForeignKey(Contact) last_contact = models.DateTimeField() notes = models.TextField(blank=True) def __str__(self): return '%s %s' %(self.last_contact,self.contact) class NoteForm (ModelForm): class Meta: model=Note ###### deprecated ####### class NoteManipulator(Note.AddManipulator): def __init__(self): # Set everything up initially using the built in manipulator Note.AddManipulator.__init__(self) newFields = [] # replacing some fields with HiddenFields for field in self.fields: if field.field_name in ('user',): field = formfields.HiddenField(field.field_name, field.is_required, field.validator_list) newFields.append(field) self.fields = newFields def note(request,id=''): if request.method == "POST": .. processing stuff here .. else: oid=request.GET.get('oid','') if id: # prepare for update inst=Note.objects.get(id=id) form=NoteForm(instance=inst) submit="Update" else: # prepare for insert # default foreign key on new record manipulator = noteManipulator() dflt={'organisation=oid': oid} errors={} ### deprecated form=NoteForm().FormWrapper(manipulator, dflt, errors) submit="Insert" return render_to_response('crm/note.html',{ 'form': form, 'id': id, 'oid': oid, 'submit': submit, }) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---