OOP noob question: Mixin properties

Micky Hulse mickyhulse.lists at gmail.com
Thu Dec 13 04:49:25 CET 2012

Dear Python Santa gurus, ;D

I have this Django mixin:


...which is used to override render_to_response() so I can output a
JSON response (the above code is pretty much straight from the Django
docs: <https://docs.djangoproject.com/en/1.3/topics/class-based-views/#more-than-just-html>).

The JSONResponseMixin() gets added to my view class like so:

class Api(JSONResponseMixin, BaseDetailView):
    # ...

Within my the mixins.py file, at the top of the file, I've added these

CACHE_TIMEOUT = 86400 # 24 hours.
CACHE_NAME = 'ad_manager_api'


I'd like to convert those constants to properties and make my
JSONResponseMixin() class more generic and portable.

Django aside, could someone provide OOP Python examples of how I could
instantiate a mixin Class and set/override its properties before
passing data to said mixin?

I hope you don't mind that this question involves Django... I'm just
looking to improve my core Python skills (so, generic Python examples
would be cool).

Many thanks in advance!


More information about the Python-list mailing list