Tuesday, October 29, 2013

Migrate all my Django projects to v1.5.5

It is really great when accomplishing something. To me, It's migrate all my Django projects to the latest stable version of Django (1.5.5, when I write this blog post).

There are something I want to take notes:

1. Replace/remove all the obsoleted methods, functions, especially the generic views. The function based generic views are replaced completely by the class based views in Django 1.5. For example:

# from django.views.generic.list_detail import object_list
# from django.views.generic.create_update import create_object

(Function-based generic views such as direct_to_template and object_list were deprecated in Django 1.3 and removed in 1.5.)

For more information about class based views and how to migrate from function based views:

+ https://docs.djangoproject.com/en/1.3/topics/generic-views-migration/
+ https://docs.djangoproject.com/en/1.5/topics/class-based-views/generic-display/


2. Replace/remove settings keywords, and add new required ones. Something like:

...
ALLOWED_HOSTS = ['localhost', 'myapp']

...


3. Apply new Django's tag rules. Such as:


Old way:

 <a href="{% url myview %}" >...</a>

Replace with:

<a href="{% url 'myview' %}" >...</a>


4. Project directory's structure:

    myproject/
        manage.py
        media/
        products/
        profiles/
        ratings/
        static/
        templates/
        myproject/
            __init__.py
            settings/
            urls.py
            wsgi.py



5. manage.py:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)