Django models. Retrieve the class of a model -
there project models.py looks this:
class page(models.model) #fields class news(page) #no fields when want retrieve page or news page this:
page = get_object_or_404(page, id=page_id)
however, when give this: page.__class__ this: main.models.page.
is there way know if page page class or news class without checking if page_id exists in news?
given page_id value there no way test whether or not id value exists entry in news table in addition page table other either trying retrieve (such page.news, , catching doesnotexist exception cases in not exist) or direct query against news manager. queries against page model's manager return page instances - have either know priori in view want news instead or test existence.
Comments
Post a Comment