Using Django 1.2,

I've got a "Niveau" class in models.py. That class contains an auto-
refering field called "niveau" as a ForeignKey field. I use this class
to store a tree structure: the "niveau" field references a "Niveau"
instance's parent.

class Niveau(models.Model):
    TYPES=( ('CAMP', 'Campagne'),
                        ('STEP', 'Etape'),
                        ('TACH', 'Tache'),
                        ('TIR', 'Tir'),)
    niveau=models.ForeignKey('self', related_name='niveau_superieur',
null=True, blank=True)
    type=models.CharField(max_length=4, choices=TYPES)


I display this class using differents forms for each level of the
"Niveau" tree using ModelForm:

One of these levels is:

class EtapeForm(ModelForm):
        niveau=models.ForeignKey('self',
related_name='niveau_superieur',verbose_name='niveau parent',
null=True, blank=True, limit_choices_to = {'type' :'CAMP'})
        class Meta:
                model = Niveau
                fields = ['type', 'nom', 'date_debut', 'date_fin', 'summary',
'conclusion', 'action', 'objectif', 'niveau',]
                widgets = { 'type': HiddenInput, }

According to 
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types-or-widgets,
this is supposed to override the "Niveau" "niveau" field but it
doesn't work.

Maybe the new "widgets" attribute to the Meta class of ModelForm could
help, but I can't find how to define choices for the Select widget in
Django's documentation.

There must be other ways to do this, but since I'm new to Django (this
is my first app) I haven't found them out yet.

Thanks,
David

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to