Re: The only click to add any class

2006-06-16 Thread Grigory Fateyev

Hello Jorge Gajon!
On Thu, 15 Jun 2006 13:15:05 -0500 you wrote:

> The hint is in the error message.
> You must pass a Region object to the region parameter,
> new_data['region'] contains only the id that the user selected from
> the select list.
> 
> You can do this:
> 
> def save(self, new_data):
> t = Town(
> region = Region.objects.get(pk=new_data['region']),
> [...]
> )

Thanks a lot for helping!

-- 
÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ!
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
-~--~~~~--~~--~--~---



Re: The only click to add any class

2006-06-15 Thread Jorge Gajon

> And when I save form, got this error:
> Invalid value: 'region' should be a  'serp2.apps.common.models.Region'> instance, not a  Request

The hint is in the error message.
You must pass a Region object to the region parameter,
new_data['region'] contains only the id that the user selected from
the select list.

You can do this:

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

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



Re: The only click to add any class

2006-06-15 Thread Grigory Fateyev

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  instance, not a  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
-~--~~~~--~~--~--~---



Re: The only click to add any class

2006-06-14 Thread Grigory Fateyev

Hello Grigory Fateyev!
On Tue, 13 Jun 2006 16:56:14 +0400 you wrote:

> 
> Hello!
> 
> We have compositely app 'Address' with lots of classes. Like: Region,
> Country, Location and etc. And to fill the only address users need to
> click some forms to add one address. It's awfully ;(
> 
> Is it possible to write (Add|Change)Manipulator to commit data from
> some forms at that time? To write form with fields from any class and
> commit data using only one click?
> 
> Thanks!

Is it not possible?

-- 
÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ!
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
-~--~~~~--~~--~--~---