OOP noob question: Mixin properties

M

Micky Hulse

Dear Python Santa gurus, ;D

I have this Django mixin:

<https://github.com/registerguard/dj...b7b0373cee7da52613c7531a/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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top