On Tue, Sep 2, 2008 at 1:27 PM, gauteh <[EMAIL PROTECTED]> wrote:

is there a different way to accomplish what im trying to do? or do i
> need to check in my view function for which subclass that exists:
> try:
>    n = items.newsitem
> except DoesNotExist:
>    pass
> try:
>    l = items.linkitem
> except DoesNotExist:
>   pass
>

There was a thread on this list from a couple weeks ago that was relevant to
your question:
http://groups.google.com/group/django-users/browse_thread/thread/52f72cffebb705e/b76c9d8c89a5574f?lnk=gst&q=vietnam#b76c9d8c89a5574f

Your above code is going to hit the database n times, once for each
subclass.  If you put a flag on the BasicItem object that indicates which
type it is, you can get that down to one lookup.  Once you have all the
correctly typed objects in memory, you can write a single tag that displays
any type. I think that type-checking like this doesn't belong in templates.

You might want to consider making the parent BasicItem class abstract, and
abandoning the BasicItem.manager.all() call.   You could replace that with
an index that you manage yourself, or write a custom query.  Since you have
no stand-alone BasicItem types, you don't need model inheritence that splits
an object's data across multiple tables.

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