20090309 ======== Surf ---- - http://code.djangoproject.com/wiki/CookBookNewFormsFieldOrdering A description of the `SortedDict.keyOrder` trick used by the patch in #8164. - http://code.djangoproject.com/wiki/CookBookNewFormsDynamicFields Dynamically add fields to a Form. - http://code.djangoproject.com/wiki/ModifiedPreorderTreeTraversal: An efficient parent/child relationship - Similar to the "category" data model above, but doesn't use recursive functions, neither multiple queries. - http://code.djangoproject.com/wiki/UsingMarkup Body fields that are rendered using markdown, restructured_text or textile, should store the raw input *and* the resulting HTML, because database columns are cheap and processing time maybe not. How to implement readonly form fields ------------------------------------- I submitted my second Ticket to Django: :djangoticket:`10442`: I saw ticket #3990 , but IMHO, if a :class:`ModelForm` has an explicit ``fields`` list, and if some of these fields are not editable, then they should be rendered as readonly widgets. That's the least surprising behaviour. Currently they are just ignored. I am trying to write a patch, but I'm new to Django. I even started with the patch: - django/forms/fields.py: :meth:`Field.__init__` has a new keyword argument "readonly". - django/forms/util.py: :func:`flatatt` now supports None values in the dictionary. These don't become a key="value" pair but a simple attribute without value. - django/forms/models.py: :func:`model_to_dict` now also adds non-ediable fields to the dictionary. I changed my working copy of Django to do the following:: >>> class ContactForm(forms.Form): ... id = forms.IntegerField(readonly=True) ... fname = forms.CharField(max_length=20) ... lname = forms.CharField(max_length=20) >>> frm = ContactForm() >>> s=frm.as_p()

But then my ticket had been already set to "wontfix". And now I agree with the Django developers because I got enlightened: Forms are not meant to contain layout. That's also why the field order (:djangoticket:`8164`) is not really important in Forms. If you want to define layout without fiddling with templates, then you'll want a :class:`Report`.