forked from rc/aircox
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
|
||||
|
@ -160,8 +160,7 @@ class SearchRoute (Route):
|
||||
name = 'search'
|
||||
|
||||
@classmethod
|
||||
def get_queryset (cl, website, model, request, **kwargs):
|
||||
q = request.GET.get('q') or ''
|
||||
def get_queryset (cl, website, model, request, q, **kwargs):
|
||||
qs = model.objects
|
||||
for search_field in model.search_fields or []:
|
||||
r = model.objects.filter(**{ search_field + '__icontains': q })
|
||||
|
@ -52,12 +52,12 @@ class PostListView (PostBaseView, ListView):
|
||||
"""
|
||||
Request availables parameters
|
||||
"""
|
||||
embed = False
|
||||
exclude = None
|
||||
order = 'desc'
|
||||
reverse = False
|
||||
fields = None
|
||||
page = 1
|
||||
embed = False # view is embedded (only the list is shown)
|
||||
exclude = None # exclude item of this id
|
||||
order = 'desc' # order of the list when query
|
||||
fields = None # fields to show
|
||||
page = 1 # page number
|
||||
q = None # query search
|
||||
|
||||
def __init__ (self, query):
|
||||
if query:
|
||||
@ -118,7 +118,7 @@ class PostListView (PostBaseView, ListView):
|
||||
|
||||
def get_context_data (self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update(self.get_base_context())
|
||||
context.update(self.get_base_context(**kwargs))
|
||||
context.update({
|
||||
'title': self.get_title(),
|
||||
})
|
||||
@ -273,7 +273,6 @@ class Section (BaseSection):
|
||||
self.object = object or self.object
|
||||
if self.object_required and not self.object:
|
||||
raise ValueError('object is required by this Section but not given')
|
||||
|
||||
return super().get(request, **kwargs)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user