More readable method annotations
This is just a very thin layer of functionality for better readability. Does not have any effect on runtime performance.
This is just a very thin layer of functionality for better readability. Does not have any effect on runtime performance.
Enables convenient adding of fields, methods and properties to Django models. Instead of: User.add_to_class('foo', models.CharField(...) User.add_to_class('bar', models.IntegerField(...) you can write: class UserMixin(ModelMixin): model = User foo = models.CharField(...) bar = models.IntegerField(...)
I needed to use class based views, but I wanted to be able to use the full name of the class in my URLconf without always having to instantiate the view class before using it. What helped me was a surprisingly simple metaclass. I can now both instantiate view classes and use the instances as view functions, OR I can simply point my URLconf to my class and have the metaclass instantiate (and call) the view class for me. This works by checking the first argument to `__call__` – if it's a `HttpRequest`, it must be an actual HTTP request because it would be nonsense to attept to instantiate a view class with an `HttpRequest` instance. The `View` base class contains a overridable before method that can be used to add a common procedure to handlers of different HTTP requests. The `before` method can modify the args and kwargs of the request handlers to be able to replace, say, `model_id` with `model`.
This snippet will monkeypatch `django.db.models.Model` to include 7 new methods: * `get_verbose_name` Because you can't access model._meta from templates * `get_verbose_name_plural` * `get_admin_change_url` * `get_admin_delete_url` * `get_admin_history_url` * `get_admin_changelist_url` * `get_admin_add_url` This snippet also gives you the template code to paste to your `base.html` so every front end model instance view of your site will show an admin toolbar for logged in users that have admin access.
eallik has posted 4 snippets.