Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Dynamic proxy models for Django

Project Description
django_dynproxy
===============

Dynamic proxy models for Django

With django_dynproxy, you can dynamically modify a Django proxy model by :
* hiding one or many fields (from the concrete parent model)
* making mandatory one or many fields (who are not mandatory in the concrete parent model)

This can be useful when you want to use inheritance in your code, but not in your database

WARNING : THIS IS AN ALPHA RELEASE. NOT RECOMMENDED FOR PRODUCTION USE

Requirements :
--------------

django>=1.4.3

Installation :
--------------

pip install django_dynproxy

Usage :
---------

1) Create a concrete model

2) Create a Django proxy model deriving from the concrete model

3) Define a metaclass using dynproxy_metaclass_factory and specify :
- which base fields you want to exclude from your proxy model
- which non-mandatory base fields you want to be mandatory your proxy model

4) Add the __metaclass__ to your proxy model class


Sample :
---------

from dynproxy.utils import dynproxy_metaclass_factory

TRAVELER_TYPE_PILOT = '1'
TRAVELER_TYPE_PASSENGER = '2'

TRAVELER_TYPES = (
(TRAVELER_TYPE_PILOT,_(u"Pilot")),
(TRAVELER_TYPE_PASSENGER,_(u"Passenger"))
)

class Traveler(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
type = models.CharField(max_length=200,choices=TRAVELER_TYPES)
passport_number = models.CharField(max_length=200,blank=True)
trigram = models.CharField(max_length=200,blank=True)
pilot_category = models.ForeignKey(PilotCategory,null=True,blank=True)


def __unicode__(self):
return "%s %s" % (self.first_name,self.last_name)

def traveler_manager_factory(traveler_type):
class _TravelerManager(Manager):
def get_query_set(self):
return super(_TravelerManager,self).get_query_set().filter(type=traveler_type)
return _TravelerManager

PilotManager = traveler_manager_factory(TRAVELER_TYPE_PILOT)
PassengerManager = traveler_manager_factory(TRAVELER_TYPE_PASSENGER)


PilotMetaclass = dynproxy_metaclass_factory(
mandatory_fields=['trigram','pilot_category'],
fields_to_exclude=['passport_number']
)

PassengerMetaclass = dynproxy_metaclass_factory(
mandatory_fields = ['passport_number'],
fields_to_exclude =['trigram','pilot_category']
)


class Pilot(Traveler):
__metaclass__ = PilotMetaclass
objects = PilotManager()
class Meta:
proxy = True

class Passenger(Traveler):
__metaclass__ = PassengerMetaclass
objects = PassengerManager()
class Meta:
proxy = True
Release History

Release History

This version
History Node

0.2.0

History Node

0.1.9

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django_dynproxy-0.2.0.zip (3.3 kB) Copy SHA256 Checksum SHA256 Source Jan 21, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting