OOP noob question: Mixin properties

Micky Hulse mickyhulse.lists at gmail.com
Wed Dec 12 22:49:25 EST 2012


Dear Python Santa gurus, ;D

I have this Django mixin:

<https://github.com/registerguard/django-ad-manager/blob/8628bfe70f6ca68cb7b0373cee7da52613c7531a/ad_manager/mixins.py>

...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
constants:

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

Question(s):

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!

Cheers,
Micky



More information about the Python-list mailing list