translate_polymorphic_Q_object: fixed test case, and made the function a member of PolymorphicObject.
Minor test fixes: warnings fixed, test_tool.py renamed as it's no test
This commit is contained in:
@@ -310,7 +310,7 @@ output the <tt class="docutils literal">ShowFieldType</tt> mixin has been used (
|
||||
<li>Fully automatic - generally makes sure that the same objects are
|
||||
returned from the database that were stored there, regardless how
|
||||
they are retrieved</li>
|
||||
<li>Only on models that request polymorphic behaviour however (and the
|
||||
<li>Only on models that request polymorphic behaviour (and the
|
||||
models inheriting from them)</li>
|
||||
<li>Full support for ForeignKeys, ManyToManyFields and OneToToneFields</li>
|
||||
<li>Filtering for classes, equivalent to python's isinstance():
|
||||
@@ -527,23 +527,17 @@ in the future).</li>
|
||||
</div>
|
||||
<div class="section" id="using-enhanced-q-objects-in-any-places">
|
||||
<h2>Using enhanced Q-objects in any Places</h2>
|
||||
<p>Sometimes it would be nice to be able to use the enhanced filter-definitions/Q-objects
|
||||
outside of polymorphic models/querysets. Example (using <tt class="docutils literal">limit_choices_to</tt>
|
||||
to filter the selection of objects in the admin):</p>
|
||||
<p>The queryset enhancements (e.g. <tt class="docutils literal">instance_of</tt>) only work as arguments
|
||||
to the member functions of a polymorphic queryset. Occationally it may
|
||||
be useful to be able to use Q objects with these enhancements in other places.
|
||||
As Django doesn't understand these enhanced Q objects, you need to
|
||||
transform them manually into normal Q objects before you can feed them
|
||||
to a Django queryset or function:</p>
|
||||
<pre class="literal-block">
|
||||
class MyModel(models.Model):
|
||||
somekey = model.ForeignKey(Model2A,
|
||||
limit_choices_to = Q(instance_of=Model2B) )
|
||||
</pre>
|
||||
<p><tt class="docutils literal">instance_of</tt> is a django_polymorphic-specific enhancement of Q objects, which the
|
||||
vanilla django function <tt class="docutils literal">ForeignKey</tt> cannot process. In such cases you can do:</p>
|
||||
<pre class="literal-block">
|
||||
from polymorphic import translate_polymorphic_Q_object
|
||||
|
||||
class MyModel(models.Model):
|
||||
somekey = model.ForeignKey(Model2A,
|
||||
limit_choices_to = translate_polymorphic_Q_object( Model2A, Q(instance_of=Model2B) ) )
|
||||
normal_q_object = ModelA.translate_polymorphic_Q_object( Q(instance_of=Model2B) )
|
||||
</pre>
|
||||
<p>This function cannot be used at model creation time however (in models.py),
|
||||
as it may need to access the ContentTypes database table.</p>
|
||||
</div>
|
||||
<div class="section" id="nicely-displaying-polymorphic-querysets">
|
||||
<h2>Nicely Displaying Polymorphic Querysets</h2>
|
||||
@@ -677,7 +671,7 @@ SQL query for every object in the result which is not of class <tt class="docuti
|
||||
that it only needs one sql request per <em>object type</em>, and not <em>per object</em>.</p>
|
||||
<div class="section" id="performance-problems-with-postgresql-mysql-and-sqlite3">
|
||||
<span id="performance"></span><h2>Performance Problems with PostgreSQL, MySQL and SQLite3</h2>
|
||||
<p>Current relational DBM systems seem to be have general problems with
|
||||
<p>Current relational DBM systems seem to have general problems with
|
||||
the SQL queries produced by object relational mappers like the Django
|
||||
ORM, if these use multi-table inheritance like Django's ORM does.
|
||||
The "inner joins" in these queries can perform very badly.
|
||||
@@ -690,12 +684,12 @@ multi table Model inheritance.</p>
|
||||
<div class="section" id="restrictions-caveats">
|
||||
<span id="restrictions"></span><h1><a class="toc-backref" href="#id8">Restrictions & Caveats</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Database Performance regarding concrete Model inheritance in general
|
||||
<li>Database Performance regarding concrete Model inheritance in general.
|
||||
Please see "Performance Problems" above.</li>
|
||||
<li>Queryset methods <tt class="docutils literal">values()</tt>, <tt class="docutils literal">values_list()</tt>, <tt class="docutils literal">select_related()</tt>,
|
||||
<tt class="docutils literal">defer()</tt> and <tt class="docutils literal">only()</tt> are not yet fully supported (see above).
|
||||
<tt class="docutils literal">extra()</tt> has one restriction: the resulting objects are required to have
|
||||
a unique primary key within the result set</li>
|
||||
a unique primary key within the result set.</li>
|
||||
<li>Django Admin Integration: There currently is no specific admin integration,
|
||||
but it would most likely make sense to have one.</li>
|
||||
<li>Diamond shaped inheritance: There seems to be a general problem
|
||||
|
||||
Reference in New Issue
Block a user