On 6-7-2012 17:14, Fabiano Martins wrote:
> My idea was centralize the validation in the Model to allow use it on
> several clients besides the primary Web page (such as a batch program, a
> web service, etc.)

Yes, and normally the clean() method is the right method, but ...
> At this moment, the database relationship yet not exists, but the
> "memory data relashionship" already exists.

you don't have access to the request object in the clean() method.

> 
> Conceptually I think that, how I can access the data that will be saved
> on the Master class, I should be able to access the data that will be
> save on related classes on the same transaction.

Yes, in the form, the view and the template. But there's no relationship
there either. There's simply a collection of named data and because you
know the names you can make the relationship.


> Now I've made a new test: I created a method "clean()" on Product class,
> and see that from it I can't access data from Master class, and I can't
> access from other instances of Product  class...
> 
> Conceptually, in the Model the data of several instances of classes on
> the same transaction can be treated as a set, or a object always be
> individually validated on Model?

The relationship does not exist. Observe:

database <=> model <=> form <=> view <=> template
  |--relationship--| |-- dictionary of names --|

So, in python there's no relationship between models. There are model
managers that fetch the relationship from the database and return a list
of objects and make it seem like there is a relationship, but the actual
link is in the database. Since the products first need to know the
primary key of the Master to make the relationship, the Master needs to
be saved first.

I would investigate the post_save signal.

-- 
Melvyn Sopacua


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