Contact Company(Contact) Person(Contact)
If I have a Contact it might be a Person or a Company and I'm looking for the best way to find out. Especially in cases where I'm listing these objects, doing a separate trial and error database query (as I show below) isn't the best solution. Actually it might be nice if the top parent class table had a content_type field (or similar to avoid coupling to contrib.contenttypes) so we could easily deduce the leaf class. >>> from peoplez.models import Contact, Company, Person >>> p = Person.objects.all()[0] >>> p <Person: Zip > >>> c = Contact.objects.all()[0] >>> c <Contact: Zip> >>> c == p False >>> dir(c) ['AddManipulator', 'ChangeManipulator', 'DoesNotExist', 'MultipleObjectsReturned', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__getattribute__', '__hash__', '__init__', '__metaclass__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__unicode__', '__weakref__', '_collect_sub_objects', '_default_manager', '_get_FIELD_display', '_get_FIELD_filename', '_get_FIELD_height', '_get_FIELD_size', '_get_FIELD_url', '_get_FIELD_width', '_get_image_dimensions', '_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order', '_get_pk_val', '_meta', '_save_FIELD_file', '_set_pk_val', '_tags_cache', 'aim', 'city', 'city_id', 'company', 'confidential', 'country', 'country_id', 'created_on', 'delete', 'description', 'dotmac', 'edit_url', 'email', 'fax', 'genres', 'get_absolute_url', 'get_next_by_created_on', 'get_previous_by_created_on', 'houseNumber', 'id', 'last_modified', 'mobile', 'msn', 'myspace', 'name', 'objects', 'person', 'pk', 'postcode', 'roles', 'save', 'save_base', 'skype', 'state', 'state_id', 'street', 'tags', 'tel', 'url', 'validate'] # here's one sloppy way : >>> c.person <Person: Zip > # I could catch this : >>> c.company Traceback (most recent call last): ... DoesNotExist: Company matching query does not exist. that won't scale of course btw. I'm using newforms-admin svn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---