I don't know how others have approached it, but I have a 'settings'
file with defaults defined in one place and reference those values via
imports in the form file and model file.  For values specific for the
app, I stick them in the models file.

models.py
---------
POST_DEFAULTS = {'status':'published'}

class Post(models.Model):
        status  = models.CharField(
                        maxlength = 15,
                        choices = PUBLICATION_STATUS,
                        default = POST_DEFAULTS['status'])

forms.py
---------
from app.models import POST_DEFAULTS,PUBLICATION_STATUS

class PostForm(forms.Form):
    status =
forms.CharField(forms.CharField(widget=forms.Select(choices=PUBLICATION_STATUS,
initial = POST_DEFAULTS['status'])

---or--- if you are doing form_for_* (I don't use those, but this
should be close)

views.py
---------
PostForm = form_for_model(Post)
PostForm.base_fields['status'].initial = POST_DEFAULTS['status']
form = PostForm()

If you use the helpers, the important thing to remember is to modify
the base_fields dict before instantiating the form.  Yet another
option, is to create a callback function passed to form_for_model.
The callback function basically gets called for every field in the
model and you have the choice of making changes for each field.  That
method always felt cumbersome compared to just changing the values you
need changed, so I can't do it off the top of my head.  A search for
formfield callback should tell you how though.


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to