changes
This commit is contained in:
@ -116,7 +116,7 @@ class RelatedPostBase (models.base.ModelBase):
|
||||
rel = attrs.get('Relation')
|
||||
rel = (rel and rel.__dict__) or {}
|
||||
|
||||
related_model = rel.get('related_model')
|
||||
related_model = rel.get('model')
|
||||
if related_model:
|
||||
attrs['related'] = models.ForeignKey(related_model)
|
||||
|
||||
@ -140,6 +140,14 @@ class RelatedPostBase (models.base.ModelBase):
|
||||
|
||||
|
||||
class RelatedPost (Post, metaclass = RelatedPostBase):
|
||||
"""
|
||||
Use this post to generate Posts that are related to an external model. An
|
||||
extra field "related" will be generated, and some bindings are possible to
|
||||
update te related object on save if desired;
|
||||
|
||||
This is done through a class name Relation inside the declaration of the new
|
||||
model.
|
||||
"""
|
||||
related = None
|
||||
|
||||
class Meta:
|
||||
@ -155,11 +163,15 @@ class RelatedPost (Post, metaclass = RelatedPostBase):
|
||||
It is a dict of { post_attr: rel_attr }
|
||||
|
||||
If there is a post_attr "thread", the corresponding rel_attr is used
|
||||
to update the post thread to the correct Post model.
|
||||
to update the post thread to the correct Post model (in order to
|
||||
establish a parent-child relation between two models)
|
||||
* thread_model: generated by the metaclass that point to the
|
||||
RelatedModel class related to the model that is the parent of
|
||||
the current related one.
|
||||
"""
|
||||
model = None
|
||||
mapping = None # values to map { post_attr: rel_attr }
|
||||
bind = False # update fields of related data on save
|
||||
thread = None
|
||||
thread_model = None
|
||||
|
||||
def get_attribute (self, attr):
|
||||
@ -175,7 +187,6 @@ class RelatedPost (Post, metaclass = RelatedPostBase):
|
||||
related object.
|
||||
"""
|
||||
relation = self._relation
|
||||
print(relation.__dict__)
|
||||
thread_model = relation.thread_model
|
||||
if not thread_model:
|
||||
return
|
||||
|
Reference in New Issue
Block a user