Basically have existing classes (produced off some UML model) from legacy code, what's the easiest method to integrate all of them with the Django model classes?

I've to date considered while using Django custom fields to serialize the course and allow that to handle persistence. (The drawback to this since other programs being able to access the database directly - whether it ever found that as being a requirement - would need to deserialize this area to be able to access the information.)

If there's anybody that may suggest some options towards the aforementioned - in ways the persistence around my existing classes could be 'swapped out' it might be greatly appreciated!

If you're attempting to move a legacy application to django, To be sure with @chrisdpratt and gradually alter convert your classes to Django models. It may need a sizable effort, so when you're ready, you are able to follow this trail:

  1. Produce a legacy application and set your legacy code there.

    Should you decide your code isn't essential, and you want to grab the information, which is saved within an SQL based server, you can test using inspectdb to produce "legacy models" which will read your computer data out of your legacy server. I would recommend to configure another DB connection known as "legacy" with this. see:

    Produce a command line test script to make certain you are able to load your legacy classes in the database. (Make certain to createOrmove atmosphere variable DJANGO_Configurations_MODULE in the spend prompt to operate scripts in the command line or see ).

  2. Make your new django models inside a new application ("myapp").

    Optionally, you should use inspectdb again to obtain a fundamental models instantly from the db. However, make certain you relabel the models to straightforward Django feel and look and remove any unnecessary fields and characteristics.

  3. Produce a script which reads the legacy data and creates it towards the new models.

  4. Migrate needed logic from old classes to new classes.

This can be used like a skeleton for that script for step three:

  # legacy/management/commands/

  from import NoArgsCommand
  import myapp.models as M
  import legacy.models as L

  import sys

  write = sys.stdout.write

  def copy_fields(old, new, mapping):
      for old_key, new_key in mapping.items():
          value = getattr(old, old_key)
          if type(value) is str:
              value = value.strip()
          if type(new_key) is tuple:
              value = new_key[0](value)
              new_key = new_key[1]
              if new_key == "name":
                  value = value[0].upper() + value[1:]
          setattr(new, new_key, value)

  def import_table(old_class, new_class, mapping):
      write("importing %s " % old_class.__name__)
      lookup = {}
      l = old_class.objects.all()
      for old in l:
          new = new_class()
          copy_fields(old, new, mapping)

          lookup[] =
          write (".")
      print " Done."
      return lookup

  class Command(NoArgsCommand):
      help = "Import data from legacy db."

      def handle_noargs(self, **options):
          Read data from legacy db to new db.
          print "Importing legacy data"

          import_table(L.X, M.X, { 'old_field' : 'new_field', 'old_field2' : 'new_field2'})
          import_table(L.Y, M.Y, { 'old_field' : 'new_field'})

          print "Done."