Dynamically constructing filters based on string input using SQLAlchemy

Here I am going to write a dynamic filter. This filter is made for python 3. It will take query or model class and filter condtion as input, It will return filtered query based on those filter condition. This is constructed using this SO answer. Function: class DynamicFilter(ModelHelper): def __init__(self, query=None, model_class=None, filter_condition=None): super().__init__(*args, **kwargs) self.query = query self.model_class = model_class self.filter_condition = filter_condition def get_query(self): ''' Returns query with all the objects :return: '''…

Keep reading

How to configure Django/Tornado in PyCharm Community Edition

I think, Pycharm is THE best IDE for developing python. But unfortunately, the professional edition is not free. But community edition is good enough for doing debugging, integrating GIT etc. Normally its easy to use the community edition for django and tornado's debugging/running if you know how to configure. Django For django's configuration, there is 5 easy steps: First: Go to edit configuration and click on it(like the below pictures). Second: Click on the (+) mark in top-left corner and add python configuration. Third: Click on the Script, and…

Keep reading

Some Useful Tools/Function for Django

I am going to share some useful Django tools/functions which are very useful(were for me atleast) to get things done. Return any model class and its properties This method will return any model class if you have the name of the class. from django.db import models def get_model_description(model_name=None, return_property_list=True): for item in models.get_models(include_auto_created=True): if item.__name__ == model_name: if return_property_list is True: return item.get_trigger_properties() else: return item return…

Keep reading

Implementation of 'Forgot/Reset Password' feature in Django

Django has its own implementation for reset/forgot password for its admin site. We are going to use that piece of code as reference to implement similar feature for a non admin-site authentication page. Although there are tons of good packages which will allow user to use their password reseting system. But if the system isn't too complex and doesn't need such authentication plugins, then reusing the django's very own implementation can be a good option. Class based view is going to be used instead of method based view(for…

Keep reading

Perodic Tasks By Celery 3.1 Example

I am assuming you have read celery docs from Celery Documentation As we know, celery can be used as a scheduler for executing asynchronous tasks in periodic cycles. Here I am going to share to do that with a code example. But I am going to avoid theoretical knowledge here because you can read them in celery documentation. First install celery: pip install django-celery. Configuring Brokers We are using django database as Broker. For detail understanding, check here: http://celery.readthedocs.org/en/latest/getting-started/brokers/django.html Making Periodic…

Keep reading