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

Working with Formset

As documentation says: A formset is a layer of abstraction to work with multiple forms on the same page. It can be best compared to a data grid. So here I am going to show a very simple django formset implementation example. Here we are going to use the following model, form, template, view: Model class Product(models.Model): name = models.CharField(max_length=50) quantity = models.IntegerField() price = models.IntegerField() class Distributor(models.Model): name = models.CharField(max_length=100) products= models.ManyToManyField(Product) These fairly simple models, where…

Keep reading

Syncdb vs Migration

While surfing through stackoverflow, I find a common question among Django users that, database not working properly; fields attribute changed, yet not working etc. Clearly because most of them used syncdb after altering fields. Well, lets make some things clear here about django syncdb and migration. What is syncdb? syncdb is a command which is executed in django shell to create tables for first time for apps which are added to INSTALLED_APPS of settings.py. Need to keep in mind about two key words: 'First Time' and 'Newly Added…

Keep reading

Sample Ajax GET/POST Request in Django

Let us make a test scenario here: A dropdown field which on change we are going to send a Get/Post request to django and return response. Let us start coding.... <select id="select_dropdown"> <option value='joshua'>joshua</option> <option value='peter'>peter</option> .... .... </select> Lets make a Ajax request after change in dropdown field. $(document).ready(function(){ $('#select_dropdown').change(function(){ var e = document.getElementById("select_dropdown"); var value = e.options[e.selectedIndex].value; $.ajax(…

Keep reading

Using IntellijIdea Within An Exisiting Virtualenv

To add virtual environment to Intellij Idea, You have added virtualenv folder's python to project sdk. Which means that virtualenv directory's python( for example venv/bin/python2.7) needs to be added to Intellij Idea project path. Here is a demonstration: First you need to go to file>project structure (in IntellijIdea) Press new in Project SDK and add new path to virtualenv's python directory like this: Go to Modules>Dependencies and set your module sdk to Python SDK which is marked on this picture: Now press ok and final…

Keep reading