Skip to content

Commit

Permalink
Merge pull request #32 from marcoshemann/master
Browse files Browse the repository at this point in the history
Added excludes for detail view template
  • Loading branch information
asifpy authored Sep 27, 2016
2 parents c965ec5 + a293b76 commit 1673fb1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions crudbuilder/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(

self.custom_modelform = self._has_crud_attr('custom_modelform')
self.modelform_excludes = self._has_crud_attr('modelform_excludes')
self.detailview_excludes = self._has_crud_attr('detailview_excludes')
self.createupdate_forms = self._has_crud_attr('createupdate_forms')

# django tables2
Expand Down
4 changes: 4 additions & 0 deletions crudbuilder/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def get_context_data(self, **kwargs):
context = super(CrudBuilderMixin, self).get_context_data(**kwargs)
model = context['view'].model
context['app_label'] = model._meta.app_label
try:
context['exclude'] = self.detailview_excludes
except:
context['exclude'] =None
context['actual_model_name'] = model.__name__.lower()
context['pluralized_model_name'] = plural(model.__name__.lower())
context['verbose_model_name'] = model._meta.verbose_name
Expand Down
2 changes: 1 addition & 1 deletion crudbuilder/templates/instance/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h3>{{object}}</h3>
</tr>
</thead>
<tbody>
{% for field in object|get_model_fields %}
{% for field in object|get_model_fields:exclude %}
<tr>
<td>{{object|get_verbose_field_name:field.name}}</td>
<td>{{object|get_value:field.name}}</td>
Expand Down
6 changes: 3 additions & 3 deletions crudbuilder/templatetags/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_value(obj, field):


@register.filter
def get_model_fields(obj):
def get_model_fields(obj, exclude=[]):
model = obj.__class__
excludes = ['pk']

Expand All @@ -39,8 +39,8 @@ def get_model_fields(obj):
getattr(model, name, None), property
):
property_fields.append(Field(name=name, verbose_name=name))

return chain(obj._meta.fields, property_fields)
ret = chain(obj._meta.fields, property_fields)
return [i for i in ret if i.name not in exclude]


@register.filter
Expand Down
1 change: 1 addition & 0 deletions crudbuilder/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def generate_detail_view(self):

name = model_class_form(self.model + 'DetailView')
detail_args = dict(
detailview_excludes = self.detailview_excludes,
model=self.get_model_class,
template_name=self.get_template('detail'),
login_required=self.check_login_required,
Expand Down

0 comments on commit 1673fb1

Please sign in to comment.