Hi All,

I have a bit of an issue that I'd like to kick around here before I start
diving into it...

I'm using the multi-db branch, which I've recently merged all of the latest
stuff in trunk into. It's all working quite nicely, my app runs on
PostgreSQL and I have to talk to an Oracle database as well (read only). My
problem is this; the legacy Oracle database has just been split into 2 dbs,
the split is by geographical region. So what I have now is 2 databases with
the same schema (and therefore the same models), and I need to get
information out of all of them! Here are the relevant models as they stand
at the moment:


### This is the "join table" (it's not really cos it spans a database) in my
app
class OSSTicketItem(models.Model):
    """Manual m2m table to refer to RANObjects from the netact app"""
    abrevs = ('RNC', 'WBTS') #This is a filter so I only get the types I'm
interested in
    def __str__(self):
        return "Ticket: %s, RANObject id: %s" % (self.ticket.id,
self.ran_object)

    ticket = models.ForeignKey('Ticket', related_name='ticket_items')
    ran_object = models.CharField("RANObject", max_length='30')

### This is the object in the Oracle db I'm interested in
class RANObject(models.Model):

    def __str__(self):
        return self.dn or self.name or 'No Name'

    CO_STATE_DICT = {
            0: 'Operational',
            2: 'Created from the network',
            3: 'Non-operational',
            9: 'To be deleted'
            }

    gid = models.IntegerField(primary_key=True, db_column="CO_GID")
    int_id = models.IntegerField(db_column="CO_INT_ID")
    parent = models.ForeignKey('self',related_name='children',\
            db_column='CO_PARENT_GID',to_field='gid')

    object_type = models.ForeignKey(RANObjectType, related_name='type_set',
\
                                    db_column="CO_OC_ID")
    CO_TC_ID = models.IntegerField(null=True, blank=True)
    CO_SC_NAME = models.TextField(blank=True)
    CO_DI_TOKEN = models.IntegerField()
    co_state = models.IntegerField(null=True, blank=True,
db_column="CO_STATE")
    CO_OBJECT_INSTANCE = models.TextField(blank=True)
    name = models.TextField(blank=True, db_column="CO_NAME")
    #CO_OC_VENDOR = models.TextField(blank=True)
    CO_OCV_SYS_VERSION = models.TextField(blank=True)
    CO_TIME_STAMP = models.DateTimeField()
    CO_SYSTEM_ID = models.IntegerField(null=True, blank=True)
    dn = models.TextField(blank=True, db_column="CO_DN")
    #CO_PARENT_GID = models.IntegerField(null=True, blank=True)
    CO_MF_GID = models.IntegerField(null=True, blank=True)
    maint_region = models.ForeignKey
('self',related_name='network_elements',\
            null=True, blank=True, to_field='gid', db_column="CO_MR_GID")
    site_object = models.ForeignKey(Site, related_name='ran_objects',
null=True,\
            blank=True, to_field='gid', db_column="CO_SO_GID")
    CO_SN_GID = models.IntegerField(null=True, blank=True)
    CO_USER_DEF_STATE = models.TextField(blank=True)
    CO_USER_DEF_ID = models.TextField(blank=True)
    host = models.TextField(blank=True, db_column="CO_MAIN_HOST")
    CO_ADMIN_STATE = models.IntegerField()
    CO_MAINTENANCE_MODE = models.IntegerField()
    CO_DB_TIME_STAMP = models.TimeField()

    @property
    def state(self):
        return self.CO_STATE_DICT[self.CO_STATE]
    @property
    def active_alarms(self):
        return self.alarms.filter(ALARM_STATUS=1).count()

    class Meta:
        db_table = 'utp_common_objects'

# Yes it's a horrible nasty schema!!

The RANObject (and all of the other classes in that app) will be present in
two separate databases and I therefore need to be able to refer to both from
the same model...

My options as I see them are:

Another field (db = models.CharField('oracle db', max_length=10) ) in the
OSSTicketItem which is a the key to the database (i.e. the
settings.OTHER_DATABASES), this will tell me where the object in question
lives. Now I need to get the other information from the database... so what
do I do?

   - A custom manager with a method that allows setting the db (via the
   ConnectionInfoDescriptor) on the fly?
   - A metaclass that changes the internals of the models in the Oracle
   db(s) to allow specifying which db to look in?
   - Both of the above?
   - Witchcraft and Voodo?
   - Any other ideas?

This is a fairly interesting problem here, and I recognize that it's WAY out
of spec for what django was designed for!!! If anyone's got any ideas, I'm
all ears!!

TIA,
Ben
-- 
Regards,
Ben Ford
[EMAIL PROTECTED]
+628111880346

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to