Skip to main content

SQLAlchemy to Django integration library

Project description

=======
Aldjemy
=======

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')

Not so shiny example demonstrate that we have M2M issues now:

User.sa.query().join(User.sa.user_groups).join(User.sa.user_groups.property.mapper.class_.group).filter(Group.sa.name=="GROUP_NAME")

And we can do more better:

from aldjemy import core
U2G = core.Cache.models['auth_user_groups']
User.sa.query().join(U2G.user).join(U2G.group).filter(Group.sa.name=="GROUP_NAME").all()

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.

Mixins
------

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

For 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 user `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.2.4.tar.gz (5.1 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for aldjemy-0.2.4.tar.gz
Algorithm Hash digest
SHA256 f4a59a43778f61c2778e6d318324be33ee378de81b775592e4735a9393ce89af
MD5 4c55b7f40f7e3ddeec720aa19f050e90
BLAKE2b-256 cacaaf833e4f9de9f1d4e9eb74a4cce28aa089b3107087da8bbe2eaa7f0bb0c4

See more details on using hashes here.

Supported by

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