Archive for the ‘Django’ Category

Making a Django POST mutable

July 9, 2010

For good reasons, the Django Request object’s POST attribute is immutable. No one wants anyone mucking around with important data there. But I had a case where I wanted to re-use some view code and it would involve using a POST object again, but with a few added parameters.

You can copy the POST data into a QueryDict, but I found that if you want to forward the actual request, you have to copy.copy() the request using the python standard copy library. Maybe this is obvious but it might save someone(like me) an hour of searching and trial/error.

def my_view(request)
    req_copy = copy.copy(request)
    req_copy.POST = request.POST.copy()
    req_copy.POST.update({'added_param':'my_value'})
    my_DRY_view(req_copy)

def my_DRY_view(req_copy)
        cool_stuff()

Django polymorphism: Mixins vs Inheritance Models

January 15, 2010

Relational databases are not the greatest storage destination for polymorphic data structures (stack overflow). Polymorphism allows you to have heirarchies of objects that perform similar actions. By defining this action once, you can re-use it for its subclasses. It makes code cleaner and easier to maintain. I experimented with a few different ways of doing some of my subclassing and came away with an approach involving mixins that I really like so far.

(more…)

Design Decision: Python and Django

December 25, 2009

Python is one of the leading professional programming languages in use today. It was the official programming language of my previous employer and, boy, am I glad I had the chance to learn it! C++ is not much of a web language these days. Many people use Java, PHP and Perl for their web programming. These are all fine languages but it is my personal opinion that they are all inferior to Python for this project.

(more…)