Why not working exampe from Django docs

41 views
Skip to first unread message

Seti Volkylany

unread,
May 18, 2016, 8:39:48 AM5/18/16
to Django users
https://docs.djangoproject.com/en/1.9/topics/http/sessions/#example

from django.contrib.sessions.backends.db import SessionStore as DBStore
from django.contrib.sessions.base_session import AbstractBaseSession
from django.db import models

class CustomSession(AbstractBaseSession):
    account_id = models.IntegerField(null=True, db_index=True)

    class Meta:
        app_label = 'mysessions'

    @classmethod
    def get_session_store_class(cls):
        return SessionStore

class SessionStore(DBStore):
    @classmethod
    def get_model_class(cls):
        return CustomSession

    def create_model_instance(self, data):
        obj = super(SessionStore, self).create_model_instance(data)
        try:
            account_id = int(data.get('_auth_user_id'))
        except (ValueError, TypeError):
            account_id = None
        obj.account_id = account_id
        return obj

In settings registered as next:

SESSION_ENGINE = 'apps.app_sessions.backends.extended_session_store'


When I made attempt create migrations, Django - silent

In [6]: !./manage.py makemigrations
No changes detected

Tim Graham

unread,
May 18, 2016, 8:54:33 AM5/18/16
to Django users
It might be that the meta class should be removed (or at least, app_label should refer to the actual label of your app):


class Meta:
    app_label = 'mysessions'

Does it work if you do that? Do you have the app in INSTALLED_APPS?
Reply all
Reply to author
Forward
0 new messages