python - Can you access a subbed-classed model from within the super-class model in the Django ORM? -
Say that I inherited the model's legacy as defined below.
If I need a list of all the articles, even if (in this case the order has been ordered in both the review and the news), I ArticleBase Once I can run a query, I have a paragraph base record to determine whether it asks both questions of a model. Received related to a review or news records, foreign keys which have recorded?
I am assuming that all paragraph examples are examples of article subsection subclasses.
A solution is to collect subclass names in ArticleBase and some methods that return the subclass or subclass objects based on that information. Since multi-table succession defines an asset at the original frequency to reach a child's example, it is all very straight forward. Paragraph Base (models.Model) from the category of Django.db import models:
This is not the only way to go about this. This, however, is a very simple and straight forward solution. Excellent stuff content type applications and generic modules that take advantage of it, they offer a variety of ways to do this, well, normally.
This article can be useful for the following in Base:
def __unicode __ (self) returns self.get_child () .__ Unicode __ ()
In that case, be aware that the failure to define __unicode __
in sub-codes, or on an event of ArticleBase (one that has not been subclassed) __Unicode __
calling will lead to an infinite recursion, thus following advice, discretion check (for example, directly in this way the RTIs An immediate stop)
Disclaimer:
This code is unwanted, I 'm convinced that there is a typo or two in it, but the original concept should be sound. There should be some flawed check in the production level code so that usage errors can be stopped.
Comments
Post a Comment