Django-plugins is a package that helps you to build apps more reusable. It is currently tested with Python 2.7, 3.2, 3.3, and 3.4 along with Django versions 1.7 and 1.8. It might well work with other versions.
By using 'Django-plugins', you can define, access plugins and plugin points.
Installation:
$ pip install django-plugins
Plugins are stored as python objects and synchronized to database called plugin models(PluginPoint, Plugin).
Both Plugin and plugin models has a name and title attributes. And each plugin point/plugin can be marked as enabled/disabled/removed using 'status' field in respective models from Django admin panel.
Plugins are the classes which are hardcoded, which means they cannot be modified directly by the users. But they can change the database objects of those plugins. In this way, you can provide the flexibility to the user to change plugins.
NOTE: You should always use plugin attributes (name, title) from model objects but not from plugins.
All defined plugins and plugin points are synchronized to database tables using Django management command 'sync plugins' or 'sync DB'. 'sync plugins' command detects the removed plugin points, plugins and marks them as 'REMOVED' in the database.
Features of 'Django-plugins':
Synchronization with the database.
Plugin management from Django admin - enable/disable, order.
Many ways to access plugins and related plugin models - access plugins from views, templates etc.
All plugin points and plugins must reside in 'plugins.py' file in your Django app.
To register/create a plugin point:
To create a plugin point, you need to sub-class 'PluginPoint' which exists in Django plugins point module.
Example:
from djangoplugins.point import PluginPoint
class TestPluginPoint(PluginPoint):
pass
Now, TestPluginPoint serves as a mount point for all its plugins. Now we have a point, we can start registering/creating plugins for it.
You can also define methods, attributes same as you would do for other classes. In turn, they will get inherited by each of its plugins.
Registering a plugin:
All individual plugins of this point need to subclass this so that they are registered as plugins for the plugin point, which means that subclassing plugin-point itself registers the plugin.
Example:
class TestPlugin(TestPluginPoint):
name = 'test-plugin-1'
title = 'Test Plugin 1'
Note: All plugins must define the name, title attributes.
Utilizing plugins:
As explained in the above section, each plugin is linked to the database record of 'Plugin' model in Django plugin. So the plugin model provides all database possibilities like filtering, sorting, searching.
* To get query set of all plugins related to plugin point, just import the plugin point and you can use 'get_plugins_qs' method.
TestPluginPoint.get_plugins_qs()
Note: This method return only enabled/active plugins.
If you need to sort or filter plugins, you should always access them via Django ORM.
You can also access plugins in templates using 'get_plugins' template tag
{% load plugins %}
{% get_plugins your_app_name.plugins.TestPluginPoint as plugins %}
<ul>
{% for plugin in plugins %}
<li> {{ plugin.title }} </li>
{% endfor %}
</ul>
To get the model instance of plugin point or plugin at any point of time, you can 'get_model' method
# Get model instance of a plugin point
testpluginpoint_obj = TestPluginPoint.get_model()
# Get model instance from plugin class.
testplugin_obj = TestPlugin.get_model()
# Get model instance by plugin name.
testplugin_obj = TestPluginPoint.get_model('test-plugin-1')
Note: 'get_model' method raises 'ObjectDoesNotExist' exception, if the object is not found.
For more details, you can refer Django-plugins official documentation here
How to maintain user session across sub domains in Django
Nowadays, people are using wildcard domains to provide same user experience across different domains. Using subdomains, we can be able to host multiple sites with …
Implementation of single sign on using auth0 in django application
As the no of applications increases, users need to create username & passwords, need to remember for each application. Users can't remember these details and, …
How to implement TokenBasedAuthentication in DjangoRestFramework?
This blog explains you how to use Token Authentication to authenticate users within a Django Application. Token Authentication is a way to authorize users by …
Understanding middleware functionality in django2.0
Understanding new style of middleware in Django2.0, the difference between old-style & new-style. How to write custom middlewares in new-style and upgrading from old-style middleware.
how to pass extra context data to serializers in django-rest-framework ?
Django rest-framework passes extra context data to serializers for the best design of rest applications. we can use "context" parameter in serializers to pass extra …
By using routers in django-rest-framework we can avoid writing of url patterns for different views. Routers will save a lot of time for developing the …
What's great about Django girls to inspire women into programming
Django girls is a non-profit organization, that helps women to learn Django programming language and to inspire them into programming. They are organizing workshops all …
Custom validations for serializer fields Django Rest Framework
we can write custom validations for serializer fields in Django Rest Framework. Validators are used to validate the data whether it is semantically valid or …
Django Custom Managers - A Manager is the interface through which database query operations are provided to Django models. At least one Manager exists for …
Introduction to API development using Django REST framework with Example
Introduction to API development with Django REST framework. You can build the API for any Django application. Pre-requisites are Django and OOPS(object oriented programming concepts) …
Django-REST Framework Object Level Permissions and User Level Permissions
Django-REST User Level Permissions and Object Level Permissions. User Level Permissions and Object level Permissions allow to serve customers based on their access levels or …
Heroku is a platform as a service (PaaS) that enables developers to build and run applications entirely in the cloud. 1. installation 2. Creating and Deploying app. 3. …
Reduce database queries in django with Conditional Expressions. By using Conditional Expressions we can use "If...Elif...Else" expressions while querying the database so that we can …
How to Create initial django migrations for existing DB schema.
Django provides the comfort database migrations from its version 1.8, with which we can avoid the usage of third party packages like south. Adding migrations …
Querying with Django Q objects: Q object encapsulates a SQL expression in a Python object that can be used in database-related operations. Using Q objects …
Using Github integration, we can get the user verified email id, general information, git hub URL, id, disk usage, public, private repo's, gists and followers, …
Django - migrating from function based views to class based views
The single most significant advantage in Django class-based views is inheritance. On a large project it's likely that we will have lots of similar views. …
By writing unit test cases, you can evaluate each code component in the initial stage itself and it'll improve your app/code performance. Which is the …
This blog describes about how to work with django-plugins. Django Plugin is a Simple Plugin Framework for Django. By using django-plugins, you can make your …
We use sorl-thumbnail for scaling images by keeping the original one intact. Sorl proven to be great tool for generating different sized images throughout website. …
Extract text with OCR for all image types in python using pytesseract
Optical Character Recognition(OCR) is the process of electronically extracting text from images or any documents like PDF and reusing it in a variety of ways …
Factory Boy is a fixtures replacement tool. It allows you to use objects customized for the current test, while only declaring the test-specific fields. For …
Payment Gateways which facilitate communication within banks and Security is an integral component of all payment gateways, as sensitive data such as Credit Card Numbers …
Django Template Tags are simple Python functions that accept a value, an optional argument, and return a value to be displayed on the page. First, In …
Python Memcached Implementation for Django project
Memcache is a memory caching system that helps web applications and mobile app backends to improve performance and scalability. We should consider using Memcache when …
This package uses double-entry bookkeeping where every transaction is recorded twice (once for the source and once for the destination). This ensures the books always …
How to customize the admin actions in list pages of Django admin?
Django by default provides automatic admin interface, that reads metadata from your models to provide a beautiful model interface where trusted users can manage content …
404 Page not found and 500 Internal server errors generally occur in every website. When these errors occurs, generally for Django application it will load …
Autocomplete with Django-Haystack and Elasticsearch with single letter querying.
Django's haystack provides autocomplete functionality. To do autocomplete effectively, the search backend(elasticsearch in this case) uses n-grams (essentially a small window passed over the string). …
Celery provides asynchronous job queues, which allows you to run Python functions in the background. Celery is on the Python Package Index (PyPi), and can …
Implement search with Django-haystack and Elasticsearch Part-1
Haystack works as search plugin for django. You can use different back ends Elastic-search, Whose, Sorl, Xapian to search objects. All backends work with same …
Django comes with a simple permissions system. It provides a way to assign permissions to specific users and groups of users. We can have permissions …
Django’s template system comes with a wide variety of built-in tags and filters designed to address the presentation logic needs of your application. You can …
E-commerce is integration is becoming almost essential for every web application now a days. There are so many payment gateways to integrate with our application. …
We always struggle to give users customization's even before they login to the system like abc.micropyramid.com and django don't know how to handle that out …
In some cases the we might want to store generic model object, rather a particular specific model as 'ForeignKey'. Generic model object means adding a …
Understanding Django model formsets in detail and their advanced usage.
Silmilar to the regular formsets, django also provide model formset that make it easy to work with django models. Django model formsets provide a way …
Using Facebook integration, we can get the user verified email id, general information, friends, pages, groups and you can post on his profile, facebook pages, …
Django template engine comes as part of django framework and its very easy, extensible and handy to develop complex web applications with simplest efforts. Lets …
Django model is the single, definitive source of data about your data. It contains the essential fields and behaviors of the data you’re storing. Generally, …
Add captcha to django web page using Python-reCaptcha
Python-reCaptcha is a pythonic and well-documented reCAPTCHA client that supports all the features of the remote API to generate and verify CAPTCHA challenges. To add …
Django forms is powerful module to help django application development in rendering html from model, validate input from http request to model specifications. And we …
Django is a high-level, free and open-source Python Web framework that encourages rapid development. Django follows the model–view–controller (MVC) architectural pattern. Django's primary goal is …
Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties
Download Django CRM
An open source CRM developed by Micropyramid Get Code Here