forked from rc/aircox
documentation
This commit is contained in:
@ -14,6 +14,10 @@ from taggit.managers import TaggableManager
|
||||
|
||||
|
||||
class Post (models.Model):
|
||||
"""
|
||||
Base model that can be used as is if wanted. Represent a generic
|
||||
publication on the website.
|
||||
"""
|
||||
thread_type = models.ForeignKey(
|
||||
ContentType,
|
||||
on_delete=models.SET_NULL,
|
||||
@ -64,6 +68,9 @@ class Post (models.Model):
|
||||
|
||||
|
||||
class Article (Post):
|
||||
"""
|
||||
Represent an article or a static page on the website.
|
||||
"""
|
||||
static_page = models.BooleanField(
|
||||
_('static page'),
|
||||
default = False,
|
||||
@ -141,12 +148,28 @@ 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;
|
||||
Post linked to an object of other model. This object is accessible through
|
||||
the field "related".
|
||||
|
||||
This is done through a class name Relation inside the declaration of the new
|
||||
model.
|
||||
It is possible to map attributes of the Post to the ones of the Related
|
||||
Object. It is also possible to automatically update post's thread based
|
||||
on the Related Object's parent if it is required.
|
||||
|
||||
Mapping can ensure that the Related Object will be updated when mapped
|
||||
fields of the Post are updated.
|
||||
|
||||
To configure the Related Post, you just need to create set attributes of
|
||||
the Relation sub-class.
|
||||
|
||||
```
|
||||
class MyModelPost(RelatedPost):
|
||||
class Relation:
|
||||
model = MyModel
|
||||
mapping = {
|
||||
'thread': 'parent_field_name',
|
||||
'title': 'name'
|
||||
}
|
||||
```
|
||||
"""
|
||||
related = None
|
||||
|
||||
@ -165,13 +188,11 @@ class RelatedPost (Post, metaclass = RelatedPostBase):
|
||||
If there is a post_attr "thread", the corresponding rel_attr is used
|
||||
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.
|
||||
* thread_model: generated by the metaclass, points to the RelatedPost
|
||||
model generated for the mapping.thread object.
|
||||
"""
|
||||
model = None
|
||||
mapping = None # values to map { post_attr: rel_attr }
|
||||
thread = None
|
||||
thread_model = None
|
||||
|
||||
def get_attribute (self, attr):
|
||||
|
Reference in New Issue
Block a user