On May 30, 2008, at 11:20 AM, jonknee wrote:

> On May 30, 10:38 am, David Zhou <[EMAIL PROTECTED]> wrote:
>> You can use also use hasattr().
>>
>> Something like
>>
>> if hasattr(person_obj, 'man'):
>>  #is man
>> elif hassattr(person_obj, 'woman'):
>>  #is woman
>> else:
>>  #is freakish mutated thing
>>
>
> How would that work exactly? It's a reverse relation, so you need to
> specify what exactly you want (e.g. the data from the Man or Woman
> table). It can't automatically go out and get it.
>
> http://www.djangoproject.com/documentation/model-api/#inheritance-and-reverse-relations

Why wouldn't that work, unless I'm misunderstanding something?

 From the docs:

 >>> p = Place.objects.filter(name="Bob's Cafe")
# If Bob's Cafe is a Restaurant object, this will give the child class:
 >>> p.restaurant

However, if p in the above example was not a Restaurant (it had been  
created directly as a Place object or was the parent of some other  
class), referring to p.restaurant would give an error.

I'm assuming he's already done:

person_obj = get_object_or_404(Person, pk=person_id)

I'm also assuming one will always create person objects through the  
Man or Woman classes.  And even if he didn't, that should still  
trigger the third default else choice.


---
David Zhou
[EMAIL PROTECTED]




--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to