Package: django-model-blocks
Themodel_blocksapp provides you with automatically generated, stylable
generic Django model template partials. It fills a gap left byadminanddatabrowseby providing filters and tags that allow your to painlessly
create templates with the following properties:Automatically generated read-only viewsCan conform to whatever URL structure you wantCan be placed as blocks on to your existing templatesIntegrate well with the rest of your projectAdd this to the top of any template:{% load model_blocks %}And drop the filter anywhere you have a model instance (e.g., DetailViews):{{ object|as_detail_block }}Quick ReferenceInstallingYou can install themodel_blocksapp from PyPI:$ pip install django-model-blocksSettingsModify yourINSTALLED_APPSsetting to include:...
model_blocks,
...Basic UsageNear the top of any template you want to use model blocks, or in a base
template, include the following line:{% load model_blocks %}Then, where you want to drop a generic model template, use:{{ object|as_detail_block }}Or:{{ object_list|as_list_block }}(NOTE:If your list has many objects, consider using pagination, as the list
may require a long time to render.)By default, the title on an object detail block will be the unicode
representation of the object, and the title on a list will be the name of the
model appended with‘ List’. To change the title, pass in a parameter:{{ object|as_detail_block:"My Special Object" }}Advanced UsageWhile using the filters remains the original and most simple way to render
the blocks, if you want/need greater control over the specifics of how certain
models render, you can use the tag notation:{% detail_block object %}

{% list_block object_list %}You can still override the title by usingwith:{% with title="My Special Object" %}
    {% detail_block object %}
{% endwith %}Yeah, if all you need to do is override the title, then stick with the filters.
However, When you drop a detail block into your template, it will automatically
render all of the referenced object’s fields, including related model fields.
This potentially results in a tree of objects in your page.  The tag notation’s
strength is revealed when you need to use a custom template for any model in
your tree.Theexample_projectin the source includes a demonstration of this feature.
In that example, there arePepulatorobjects, and each one may have severalKnuckleobjects and severalJambobjects.  However, eachKnucklehas
a field referring to the URL of an image.  On ourPepulatordetail page, we
want all of ourKuckleobjects andJambobjects shown.  The default
template is sufficient forJambobjects, but we have to provide a custom
template (based on the default) for eachKnuckle.  So, we render thePepulatordetail like so:{% with pepulator_factory_knuckle_detail_template="pepulator_factory/knuckle_detail.html" %}
    {% detail_block pepulator %}
{% endwith %}Voila!  For more information, check out thepepulator_detail.htmlandknuckle_detail.htmlfiles.Help OutFound a bug? File an issue atGithub. Have an improvement? Fork
it and add it, or if you can’t code it, File anissueand we’ll do it.Are you using or thinking of usingdjango-model-filters?  Pleasedrop a
lineand let us know what for.
Knowing how people use it in the wild will help us make it better!DevelopmentDownload the code and then:$ pip install -r requirements.txtRunning TestsEven simple packages need tests:$ python tests.py --with-coverage --cover-package=model_blockRun it before and after you make any changes.  Try to not let that number drop.