Hi!
I have a modelForm for some model. Example Article:

class Article(models.Model)
      title = models.CharField(max_length=255)
      price = models.IntegerField()
      currency = models.IntegerField()

class ArticleForm(forms.ModelForm)
      price = MyPriceFied(choices = CURRENCY_CHOICES)

      class Meta:
            model = Article
            fields = ['title', 'price']

And i have a MyPriceField(forms.MiltiValueField) and
SinteticWidget(forms.MultiWidget)

class MyPriceField(forms.MultiValueField):
    '''
    Field witch contains with two widgets input and select.
    Select's choices set in "choices" param.
    '''
    def __init__(self, choices = (), *args, **kwargs):
        fields = (
            forms.CharField(),
            forms.ChoiceField(choices = choices),
        )
        widget_list = (
                    forms.TextInput(),
                    forms.Select(choices = choices),
                )
        self.widget = SinteticWidget(widgets = widget_list)
        super(MyPriceField, self).__init__(fields, choices, *args,
**kwargs)

This work fine. In template for field price rendered two controls
input type text and select.
But i have problem with submiting form. I have no idea how can i
create instance of Article class by form.save().
Becouse in form i have one field but in model i have two.

Can somebody help me? Can some one advise algorithm that can be used
to implement this?
Maybe it's not really)))
Thanks

Sorry for my english))

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to