Using Django ORM outside views (i.e. in HTTP Session Store)


I have followed the documentation to use the Django ORM, and it seems to be working as expected (i.e. makemigrations and migrate work, session: inside a view works).

However, when I try to use the Django ORM to implement a database-backed SessionStore (in the load and save methods), I can’t figure out where to use the Session object imported using “from apistar.backends.django_orm import Session”.

I attempted to use:
orm_session = Session()
Session.HTTPSession.objects.get(yadda yadda yadda)

But it failed, as it needs an instance of DjangoORM fed into it. I think I could probably hack around this by initializing everything needed in the chain, but if there’s a way to do it by grabbing the ‘Session’ being used by the view before or after HTTP sessions are grabbed, I’d love to use that.


Looks like this is trying to do something similar, but in a more general way:


maybe :

from apistar.backends.django_orm import DjangoORM


Right - I tried that yesterday, but it complains the ORM was already set
up. I just don’t have access to the instance in my session backend

I went back to DRF, I think included batteries are a bit too important to
me right now :slight_smile: