Skip to content

Instantly share code, notes, and snippets.

@mattrobenolt
Forked from DamianZaremba/insanity.py
Last active December 10, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrobenolt/4472625 to your computer and use it in GitHub Desktop.
Save mattrobenolt/4472625 to your computer and use it in GitHub Desktop.
from django.db import models
class DeviceA(object):
def do_something(self, string='Hello'):
print "Device A something '%s'" % string
def do_something_else(self):
print "Device A something else"
class DeviceB(object):
def do_something(self, string='Hello'):
print "Device B something '%s'" % string
def do_something_else(self):
print "Device B something else"
class DeviceC(object):
def do_something(self, string='Hello'):
print "Device C something '%s'" % string
def do_something_else(self):
print "Device C something else"
class Device(models.Model):
_device = None
DEVICE_TYPES = (
('A', 'Device A'),
('B', 'Device B'),
('C', 'Device C'),
)
type = models.CharField(max_length=1, choices=DEVICE_TYPES)
@property
def device(self):
if self._device is None:
if self.type == 'A':
self._device = DeviceA()
elif self.type == 'B':
self._device = DeviceB()
elif self.type == 'C':
self._device = DeviceC()
return self._device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment