<p>大多数ORM模型要么支持回引用(引用字段的目标模型被赋予一个指向引用对象的额外属性),要么允许您通过其他方式指定关系。在</p>
<p>Redisco没有我可以发现的反向引用,但是它支持字符串引用。如果传入一个字符串,它将被解释为与<code>__name__</code>属性匹配的模型名:</p>
<pre><code>class Room(models.Model):
players = models.ListField('Player', required = True)
</code></pre>
<p>这完全避开了进口问题。在</p>
<p>从<a href="https://github.com/kiddouk/redisco/blob/269a3b9affe299814162369ed4fbebf2c927b77c/redisco/models/attributes.py#L248-L259" rel="nofollow">^{<cd2>} docstring</a>:</p>
<blockquote>
<p>target_type -- can be a Python object or a redisco model class.</p>
<p>If target_type is not a redisco model class, the target_type should
also a callable that casts the (string) value of a list element into
target_type. E.g. str, unicode, int, float.</p>
<p>ListField also accepts a string that refers to a redisco model.</p>
</blockquote>
<p><a href="https://github.com/kiddouk/redisco/blob/269a3b9affe299814162369ed4fbebf2c927b77c/redisco/models/attributes.py#L297-L304" rel="nofollow">code to resolve the name</a>使用函数<a href="https://github.com/kiddouk/redisco/blob/fc141d86071aaf86e62282f1e64e8d1721da4287/redisco/models/base.py#L713-L720" rel="nofollow">^{<cd3>}</a>解析字符串,该函数只搜索<code>models.Model</code>的所有子类,匹配<code>__name__</code>。在</p>
<p>它将在验证新值或第一次检索现有值时解析名称,此时<code>Player</code>子类已经导入。在</p>