asifpy / django-crudbuilder

Generic CRUD implementation in Django
https://django-crudbuilder.readthedocs.org/en/latest/index.html
Apache License 2.0
193 stars 67 forks source link

Models should have a render name attribute [Enhancement] #24

Closed fmanzoor closed 7 years ago

fmanzoor commented 7 years ago

I have had the opportunity to use this wonderful library. I think that the models should a have field which should contain their "render name". Consider a model named FooBar, currently that model's name will be rendered as Foobar as per list.html. I suggest that we add following inside CrudBuilderMixin class

if hasattr(model , 'render_name'):
  context['model_render_name'] = getattr(model , 'render_name')
else:
  context['model_render_name'] = model.__name__.lower()
  # or some other fallback field or value we may like

We can just now call model_render_name inside our template to make our life easy and UI/UX meaningful. Let me know if I am thinking or even doing it wrong way.

wadevries commented 7 years ago

I agree with the need for a sort of 'display' version of the model name, but I think we should simply include the model's verbose_name and verbose_name_plural (see Django docs) next to the actual_model_name and pluralized_model_name.

I have fixed this in a branch on my fork; I'll make a PR out of it.