3 ms·
For Django, the trick is to implement an MVC pattern: let a class sit in-between a model and its set of views and pilot the views from there, like the admin, dr
by 1337shadow 7y ago
For Django, the trick is to implement an MVC pattern: let a class sit in-between a model and its set of views and pilot the views from there, like the admin, drf and others.
However, the admin does not leverage the Django ecosystem, django-tables2, django-filter, and so on. Also, it's kind of moving slowly because they must try to respect backward compatibility.
I maintain CRUDLFA+ and I love it:
- lets each view define its own url generation method: the controller will use that to generate the urls for a model
- each controller defines a get_queryset method which has a request parameter, allowing you to define what objects a user may see
- each view defines a has_perm method, as such a user may see a bunch of objects, but not necessarily execute all views on it,
- the default list view wraps django-tables2, django-filter, django-search, and generates a per-object menu, by iterating over each view of the controller and testing it with has_perm, as such a user will see an object menu with each view it can execute on an object, with no overhead
- allows you to override views in many ways
- works with non-managed models (models that are not backed with a database table)
- can be used for frontend pages too (admin is really limited to being a back-office),
Clearly, CRUDLFA+ goes beyond "basic crud", but I would never code a Django view without it ever again though.
However, so far I make it for my personal use and even though it's been in use on governmental production for a couple of years now, I wouldn't recommend it for beginners. If you're a Django expert and get your kicks out of trying new patterns then you might spend some good times with it.
https://yourlabs.io/oss/yourlabs https://yourlabs.io/oss/yourlabs
https://gitpitch.com/yourlabs/crudlfap https://gitpitch.com/yourlabs/crudlfap
We're in the (slow) process of replacing Jinja2 in it with Ryzom ( https://yourlabs.io/oss/ryzom https://yourlabs.io/oss/ryzom ) , a component-based HTML renderer which supports data-binding and that we are looking forward to integrate or isomorphic research (from https://yourlabs.io/oss/chp https://yourlabs.io/oss/chp ) into. When that's over we will release v1.
- raihansaputra 7y agoThis is really interesting. Will take a look on how this works for me!
- raihansaputra 7y agoI'm really interested to try, but the yourlabs.io repo is locked down. Where can I see the CRDLFA+ codebase?