Skip to main content

SQLAlchemy to Django integration library

Project description

Whats new?

2011-12-15:

  • Add M2M models generations. Storing them on core.Cache.models.

2011-12-14:

  • Added M2M fields generation. Now we dont generate models for m2m tables.

  • Sqlite datetime double conversion fix

Before:

  • mixins support

Base

Small package for integration SQLAlchemy into existent Django project. Primarily use case of package is building complex queries that not possible in Django ORM.

You need to include aldjemy to the end of INSTALLED_APPS. On models importing aldjemy will read all models and contribute sa attribute to them. sa attribute is a class, mapped to Table class.

Internally aldjemy generate tables from Django models. Its important distinction from standart decision with reflection.

Code example:

User.sa.query().filter(User.sa.username=='Brubeck')

M2M sample:

User.sa.query().join(User.sa.groups).filter(Group.sa.name=="GROUP_NAME")

Explicit joins is part of SQLAlchemy philosophy, so aldjemy cant get you Django expirience. But aldjemy is not positioned as Django ORM drop-in replacement. Its helper for special situations.

We have some staff in the aldjemy cache too:

from aldjemy import core
core.Cache.models # All generated models
core.get_tables() # All tables, and M2M tables too

You can use this staff if you need - may be you want to build queries with tables, or something like this.

Settings

You can add your own field types to map django types to sqlalchemy ones with ALDJEMY_DATA_TYPES settings parameter.

Parameter must be a dict, keys is result of field.get_internal_type(), value must be a one arg function. You can get idea from aldjemy.types.

Mixins

Often django models have helper function and properties that helps to represent models data (__unicode__), or represent some model based logic.

To integrate it with aldjemy models you can put this methods to separate mixin:

class TaskMixin(object):
    def __unicode__(self):
        return self.code

class Task(TaskMixin, models.Model):
    aldjemy_mixin = TaskMixin
    code = models.CharField(_('code'), max_length=32, unique=True)

Viola! You can use unicode on aldjemy classes, because this mixin will be mixed into generated aldjemy model.

Project details


Download files

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

Source Distribution

aldjemy-0.3.7.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file aldjemy-0.3.7.tar.gz.

File metadata

  • Download URL: aldjemy-0.3.7.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aldjemy-0.3.7.tar.gz
Algorithm Hash digest
SHA256 dbfc06794ecafb85400618de0435ae660402fe98418c20512586ea22376d3ee4
MD5 d96e51730d129ff226ad6d0cdad8fc33
BLAKE2b-256 6bfd6c56549dffb1dd5a292b9aac3b7aee067183e3992e4b11fa6d2c25553234

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page