Sunday, August 26, 2012

widget construction issue

Hi,

I built a widget class that inherits form MultiWidget and it looks like this :

class GridWidget(forms.MultiWidget):

    def __init__(self, attrs=None, queryset=None):
        self.queryset = queryset 
        _widgets = []
        for record in self.queryset:
            .
            do stuff
            .
        super(GridWidget, self).__init__(_widgets, attrs)

This basically adds widgets to the _widgets var based on the queryset. 

Then I have some form that has a field like :

class PersonAdminForm(forms.ModelForm):

          attrs = MultiTypeField( \
                    label='Attributes',
                    queryset=Attribute.objects.all()
                    widget=GridWidget(queryset=Attribute.objects.all()),
                    )

The thing is that the GridWidget.__init__ method does not get executed
each time I access the form that contains it, so if the queryset changes the
widget gets 'obsolete'.

Is this some cache issue ? is there any way to force the widget construction each time i
access the form containing it ?

--
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment