I have a certain class structure in my app, that currently utilizes django for presentation. I was not using the model layer at all, - the database interaction routines are hand-written.
I am, however, considering the possibility of actually using django to its full potential and actually using the database-abstraction layer. The question is how to best integrate my existing class structure with the model layer.
An example class:
class UpperClass(base):
def __init__(self, attr1, attr2):
self.attr1 = attr1
self.attr2 = attr2
# attr1 and attr2 are actually instances of, say,
# CustomType1 and CustomType2
Sow here is how am I going to map this to a django model:
class UpperClass(models.Model):
attr1 = CustomType1Field(...)
attr2 = CustomType2Field(...)
That's straightforward enough - all the serialization and validation stuff is already written, so it will not be hard at all to conjure up the custom field classes for CustomType1 and CustomType2.
The real question is, where do I put the custom (not-database-related) behaviour of the actual UpperClass. In my understanding, models are there for "getting things in and out of the database", but where does the behaviour go then? Do I embed the non-database-related methods in the Model instances of the UpperClass? Really, I am at a loss here. Hope this makes at least partial sense to you.