This document attempts to teach the patterns you can use, and at the same time go through every feature. The document strives to teach CRUDLFA+ as efficiently as possible. If it becomes too long, we will see how we refactor the document, until then, it serves as main documentation. Please contribute any modification you feel this document needs to fit its purpose.
CRUDLFA+ strives to provide a modern UI for Django generic views out of the box, but all defaults should also be overiddable as conveniently as possible. It turns out that Django performs extremely well already, but by pushing Django’s philosophy such as DRY as far as possible, even in the client side code world.
Enable in your project¶
We’re going to setup
INSTALLED_APPS before we begin.
We will review the minimal settings in this tutorial, but you can
consult the default settings available for your crudlfap version in
CRUDLFA+ uses Jinja2 templates with a quite extended configuration. Options to enable them are using any of these in your settings:
CRUDLFA+ leverages apps from the Django ecosystem.
crudlfap.settings.CRUDLFAP_TEMPLATE_BACKEND. To help make this a
pleasant experience, CRUDLFAP+ splits the INSTALLED_APPS setting into multiple
settings you can import and mix together:
Define a Router¶
Register a CRUD with default views using Router.register()¶
Just add a
crudlfap.py file in one of your installed apps, and the
DefaultConfig will autodiscover them, this example
shows how to enable the default CRUD for a custom model:
from crudlfap import crudlfap from .models import Artist crudlfap.Router( Artist, fields='__all__', # Optionnal hack to allow unauthenticated access: allowed=lambda view: True ).register()
Custom view parameters with View.clone()¶
If you want to specify views in the router:
.. literalinclude:: ../src/crudlfap_example/song/crudlfap.py
clone() classmethod will
define a subclass on the fly with the given attributes.
The easiest configuration is to generate patterns from the default registry:
from crudlfap import crudlfap urlpatterns = [ crudlfap.site.urlpattern ]
Or, to sit in
urlpatterns = [ crudlfap.site.get_urlpattern('admin'), # your patterns .. ]