It seems I have to develop a custom django html widget
same concept on this page (look at the render method)
http://www.huyng.com/archives/django-custom-form-widget-for-dictionary-and-tuple-key-value-pairs/661/

so apparently I need a subclass of TextInput widget with a different
render method.

Note: I tried pretty much everything from the modelform such as
setting the 'initial' parameter in the forms.Charfield, but the
value is overwritten by the instance fields values.

26 class AssignmentEditForm(ModelForm):
50    def __init__(self, *args, **kwargs):
 51         super(AssignmentEditForm, self).__init__(*args, **kwargs)
 52
 53         tagString = 'toto'
 54         #if 'instance' in kwargs:
 55         #    assignment = kwargs['instance']
 56         #    tagString = ' '.join(tag.name for tag in
assignment.tag_set.all())
 57         #self.fields['tag_set'].widget =
forms.TextInput(attrs={'size':70, })
 58         self.fields['tag_set'].widget.attrs.update({
 59             'size':70,
 60             'class': "toto",
 61             'value': "toto",
 62             })
 63         self.fields['tag_set'].initial='toto'

Nothing in the above works...
So custom textinput widget ....



On Sun, Dec 26, 2010 at 1:20 PM, Emmanuel Mayssat <emays...@gmail.com> wrote:
> On Sun, Dec 26, 2010 at 1:15 PM, Emmanuel Mayssat <emays...@gmail.com> wrote:
>> Hello,
>>
>> I have a modelform with a model which include a models.many_to_many field.
>> By default the modelform represents those m2m entries with a
>> multiplechoice field
>>
>> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>> example:
>> tag_set = forms.ModelMultipleChoiceField(queryset=Tag.objects.all())
>>
>> 1/ when I initialize my model form (form(instance=defaultinstance)), I
>> would like the m2m entries to
>> appear as a form.TextInput with default value of 
>> defaultinstance.tag_set.all()
>>
>
> Here the question how do I get the defaultinstance tags?
> Maybe self.instance.tag_set.all() ?!?!?
>
> How do I populate my widget?
> forms.TextInput(attrs={'size':70}, default=????????),
>

-- 
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