Hi,

I've been struggling with this for the past two weeks, and i think it's
time to ask.

I have and admin form that has a ModelMultipleChoiceField that is used to
display
a ManyToMany model field that specifies a through model

class Person(models.Model):
    name = models.CharField(max_length=10)
    attributes = models.ManyToManyField('Attribute',through='Has',
                                        blank=True, null=True)

class Has(models.Model):
    person = models.ForeignKey('Person')
    attribute = models.ForeignKey('Attribute')
    value = models.CharField(max_length=10)


class Attribute(models.Model):
    name = models.CharField(max_length=10)
    atype = models.CharField(max_length=2,
                                          choices=(('TF','true/false'),
                                                       ('IN','text')))


class PersonAdminForm(forms.ModelForm):

    class Meta:
        model = Person

    attrs = forms.ModelMultipleChoiceField( \
                    label='Attributes',
                    queryset=Attribute.objects.all(),
                    widget=forms.CheckboxSelectMultiple(),
                    )


This CheckboxSelectMultiple works fine, but I want to be able to render
each relation according to the Attribute.atype value, meaning if it is TF,
then tender it as a CheckBox, if it is IN the render it as an InputText

I inherited from CheckboxSelectMultiple so it does that, but then when I'm
on the admin form and for one specific attribute of type IN, rendered as a
TextInput,  I set a value (let's say 500) and then press save , the method

SelectMultiple.value_from_datadict gets called and passed as data :

<QueryDict: {u'csrfmiddlewaretoken': [u'GWLnuoTSTjjLmpYOizodBA4VA1FmwdQw'],
u'_continue': [u'Save and continue editing'], u'name': [u'nico'], u'attrs':
[ u'2']}>

And this is what has been driving me nuts!

u'attrs': [ u'2'],

As you can see it only passes the id of the attribute, not the id and the
value. What I
need is something like

u'attrs': [ (u'2','500')],

Any ideas on how to fix this ?

Thanks!

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

Reply via email to