Hello Malcolm Tredinnick!
On Thu, 15 Jun 2006 12:51:33 +1000 you wrote:

> 
> On Tue, 2006-06-13 at 16:56 +0400, Grigory Fateyev wrote:
> Create your form to collect the data you need. Make the submit button
> on that form send you to a view method to handle the submission as per
> normal (see [1]). Then, write a custom manipulator and use it in your
> form processing function as described in [2]. 
> 
> In that example, where it says "# Send e-mail using new data here...",
> you would use the Python database API [3] and the data you now have
> from your form to create your new objects and save them. If your
> various models are inter-related via ManyToManyField and ForeignKey
> attributes, you will also want to have a look at the section called
> "Related objects" in the database API docs to see how to link them
> together.

Thanks Malcolm for very useful answer!

Now I can add data to any models as wants. But have small problem with
SelectField.

I have this class:
class CommonManipulator(forms.Manipulator):
    def __init__(self, pk=None):
        self.fields = (
            forms.SelectField(field_name='region',
choices=[('','-------')] + [(o.id, o) for o in Region.objects.all()]), 
        [...]
        )

    def save(self, new_data):
        t = Town(
            region=new_data['region'],
            [...]
        )

And when I save form, got this error:
Invalid value: 'region' should be a <class
'serp2.apps.common.models.Region'> instance, not a <type 'str'> Request
Method: POST Request URL: http://localhost:8000/common/add_town/ 
Exception Type:         TypeError
Exception Value:        Invalid value: 'region' should be a instance,
not a 
Exception Location:/home/greg/www/django_src/django/db/models/base.py in 
__init__,
line 102

What can it be?

-- 
÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ!
greg [at] anastasia [dot] ru çÒÉÇÏÒÉÊ.

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to