#!/usr/bin/env python
# -*- coding: utf-8 -*-
########## THIS NOW WORKS! ##########
UNSUITABLE_ENVIRONMENT_ERROR =
"This program requires at least Python 2.6 and Linux"
import sys
import struct
import os
from array import array
# +++ Check environment
try:
import platform # Introduced in Python 2.3
except ImportError:
print >>sys.stderr, UNSUITABLE_ENVIRONMENT_ERROR
if platform.system() != "Linux":
print >>sys.stderr, UNSUITABLE_ENVIRONMENT_ERROR
if platform.python_version_tuple()[:2] < (2, 6):
print >>sys.stderr, UNSUITABLE_ENVIRONMENT_ERROR
# --- Check environment
HDIO_GETGEO = 0x301 # Linux
import fcntl
def get_disk_geometry(fd):
geometry = array( c ,"XXXXXXXX")
fcntl.ioctl(fd, HDIO_GETGEO, geometry, True)
heads, sectors, cylinders, start =
struct.unpack("BBHL",geometry.tostring())
return { heads : heads, cylinders : cylinders, sectors : sectors, "start": start }
from pprint import pprint
fd=os.open("/dev/sdb", os.O_RDWR)
pprint(get_disk_geometry(fd))
Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...