{"id":13491356,"url":"https://github.com/sorl/django-primate","last_synced_at":"2026-03-09T16:03:58.050Z","repository":{"id":1405932,"uuid":"1457355","full_name":"sorl/django-primate","owner":"sorl","description":"A Modular Django User","archived":false,"fork":false,"pushed_at":"2011-08-25T08:50:38.000Z","size":484,"stargazers_count":62,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-17T03:20:12.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sorl.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-03-09T01:41:26.000Z","updated_at":"2024-02-15T02:06:22.000Z","dependencies_parsed_at":"2022-08-16T13:15:23.625Z","dependency_job_id":null,"html_url":"https://github.com/sorl/django-primate","commit_stats":null,"previous_names":["aino/django-primate"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sorl/django-primate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sorl%2Fdjango-primate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sorl%2Fdjango-primate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sorl%2Fdjango-primate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sorl%2Fdjango-primate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sorl","download_url":"https://codeload.github.com/sorl/django-primate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sorl%2Fdjango-primate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30301532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T14:33:48.460Z","status":"ssl_error","status_checked_at":"2026-03-09T14:33:48.027Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:00:56.080Z","updated_at":"2026-03-09T16:03:58.007Z","avatar_url":"https://github.com/sorl.png","language":"Python","funding_links":[],"categories":["Libs"],"sub_categories":["Other"],"readme":"django-primate\n==============\n\n- A modular django user.\n\nI am not going to discuss if this is a good idea or not. This Django\napplication monkey patches django in order to have a custom User model that\nplugs into the ``django.contrib.auth`` application.\n\n\nInstallation\n------------\nFirst of all install the module by checking out the latest code or use pip::\n\n    pip install django-primate\n\nIn order to monkey patch we need to do this early. I have created a small\nmodified ``manage.py`` file that you can use for your development. This sets up\nyour environment and right before you run your management command (such as\n``runserver``) we apply the patch. Copy this into your project and overwrite the\ndefault ``manage.py``::\n\n    #!/usr/bin/env python\n    from django.core.management import setup_environ, ManagementUtility\n    import imp\n    try:\n        imp.find_module('settings') # Assumed to be in the same directory.\n    except ImportError:\n        import sys\n        sys.stderr.write(\n            \"Error: Can't find the file 'settings.py' in the directory \"\n            \"containing %r. It appears you've customized things.\\nYou'll have to \"\n            \"run django-admin.py, passing it your settings module.\\n\" % __file__\n            )\n        sys.exit(1)\n\n    import settings\n\n    if __name__ == \"__main__\":\n        setup_environ(settings)\n        import primate\n        primate.patch()\n        ManagementUtility().execute()\n\nTo monkey patch your deployment you would apply the patch right after setting up\nthe ``DJANGO_SETTINGS_MODULE``.\n\n\nNow add ``django.contrib.auth`` to your ``INSTALLED_APPS``\n\n\nUsing\n-----\nAfter installing this patch you effectively have no User model at all. You have\nto create one on your own and define it in your settings. I will give you an\nexample on how to do this using the provided ``UserBase`` class.\n\n``project/users/models.py``::\n\n    from primate.models import UserBase, UserMeta\n    from django.db import models\n\n    class CustomUser(UserBase):\n        __metaclass__ = UserMeta\n        name = models.CharField(max_length=500, default='Jon Deg')\n        title = models.CharField(max_length=20, blank=True)\n\n\n``settings.py``::\n\n    ``AUTH_USER_MODEL = 'users.models.CustomUser'``\n\n\nNow you can import this model by ``from django.contrib.auth.models import\nUser`` or ``from project.users.models import CustomUser``\n\n\nCustom fields and overriding default fields\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nIt's simple\n\n- To add a field just add a field to the model as you would normally.\n- To override a field just override the field name and it will be used instead\n  of the one defined in ``UserBase``.\n\nThe overriding feature is something special not available in normal Django\nmodel abstract classes and is done in the custom metaclass. You can also remove\nfields defined in the ``UserBase`` class by altering the metaclass a little, you\ncan have a look in the code, its a really simple.\n\n\nAdmin\n^^^^^\nTo make the admin work I have made the monkey patch ``primate.patch`` patch the\n``admin.autodiscover`` so that it does not register the default admin class for\n``django.contrib.auth.User``. This means that you will need to register that\nyour self. The easiest way to do that is to first add ``users`` to your\n``INSTALLED_APPS`` and then add something like this to ``users/admin.py``::\n\n    from primate.admin import UserAdminBase\n    from django.contrib import admin\n    from django.contrib.auth.models import User\n\n\n    class UserAdmin(UserAdminBase):\n        pass\n\n\n    admin.site.register(User, UserAdmin)\n\n\nWhat's new in UserBase compared to django.contrib.auth.models.User?\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nI have made some minor changes:\n\n1. Removed ``first_name`` and ``last_name``\n\n2. Added ``name``\n\n3. ``username`` is now max 50 chars\n\n4. Made ``email`` unique\n\n5. ``get_profile`` method just returns self\n\n\nAs stated earlier, you can now change all this, remove add and override fields\nin your user model.\n\n\nSouth\n^^^^^\nI was worried, this is a major feature, luckily Andrew already thought of this:\nquote from the documentation under ``SOUTH_MIGRATION_MODULES``:\n\n\"Note that the keys in this dictionary are ‘app labels’, not the full paths to\napps; for example, were I to provide a migrations directory for\ndjango.contrib.auth, I'd want to use auth as the key here.\"\n\nSo the time has come, just add this to your settings::\n\n    SOUTH_MIGRATION_MODULES = {\n        'auth': 'users.migrations',\n    }\n\n\nAlternative password hashing\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nSHA-1 is the default django hashing algorithm for passwords. Some may not agree\nthat this is the best choice. ``django-primate`` makes it simple for you to use\nalternative hashing as you can just override the ``check_password`` and\n``set_password`` methods in your custom user model. Since bcrypt is a good\nchoice there is a simple way for you to implement hashing using this::\n\n    # project/users/models.py\n\n    from primate.models import UserBase, UserMeta, BcryptMixin\n    from django.db import models\n\n    class CustomUser(BcryptMixin, UserBase):\n        __metaclass__ = UserMeta\n\n\nNote that this will update all passwords on authorization success to use bcrypt.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsorl%2Fdjango-primate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsorl%2Fdjango-primate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsorl%2Fdjango-primate/lists"}