Hi,

2012/7/7 Tomas Neme <[email protected]>:
>> and I do
>> for fruit in Fruits.objects.all(): fruit.rott()
>>
>> will anything happen at all? I know in C++ this would work... ;-)
>>
>> on database-level I know how to do it, I just don't know if the django
>> abstraction handles this automalically.
>
> I.. don't know. I'd think yes, at least I wonder otherwise how does
> the DB keep coherent if you do
> BaseModel.objects.filter(foo=bar).delete(). "CASCADE" would deal with
> it in PG, but mysql sometimes lacks that, and sqlite doesn't handle
> foreign keys at all.
>
> but you probably need to make some tests to make sure. It'd be quite
> easy to do it from the shell
>

Ok, I did some tests today and read in the django sources.
It seems to me, that an abstract model class has no Manager attached,
at least not by default. I see that, because my
AbstractFruits.objects.all() says "AttributeError: type object
'AbstractFruits' has no attribute 'objects'", and as I understand
objects is the Manager() class.

So it should be technically possible to implement a manager class for
abstract models which does a join of all subclasses... maybe somebody
takes the challange ;-)

>> Seems I have too little faith in the capabilities of python ;-)
>
> Yah, and about that.. what you said WOULD work for any Objects of a
> subclassed class in python, as it would in C. Actually, since you
> don't declare types in python, you don't really know the class of your
> parameters unless you ask, it is the concept of duck-typing that gets
> used strongliest in python (you ask the parameter to respond to a
> certain interface, you don't care what type it is).

so I need to use a lot of try/except blocks or is there another
concept I missed?
Sorry, it's getting off-topic, it's just following my "learning curve"... ;-)

> The question is not whether python is able to know what the real class
> of an object is, but rather whether django knows the real model of an
> object it got from a supermodel's table.
>

which is possible, as long as the developer imports the whole models
file with all subclasses. If you import only certain models, you might
not get what you expect. But that could be seen as case of the GIGO
principle ;-)

Regards,
Daniel

-- 
Daniel Walz - [email protected]
Bremen, Germany

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

Reply via email to