gs-django-modelplus


Namegs-django-modelplus JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryReusable abstract django models
upload_time2025-08-26 06:45:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseCopyright (c) 2025 Sandi Šaban Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords django models
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # gs-django-modelplus

Django application `modelplus` defines reusable abstract models that can be used to quickly and consistently add common fields and their functionalities to your models.


## Installation

If using Astral's uv for virtual environment and project dependencies:

```
$ uv add gs-django-modelplus
```

Or, with pip in your virtual environment:

```
$ pip install gs-django-modelplus
```


## Quick setup

Add application to `settings.py`:

```
INSTALLED_APPS = [
    ...
    "modelplus",
]
```

If using abstract model `UserstampableModel`, `CurrentUserMiddleware` has be added to `settings.py` after `django.contrib.auth.middleware.AuthenticationMiddleware`:

```
MIDDLEWARE = [
    ...
    "modelplus.middleware.CurrentUserMiddleware",
]
```


## Abstract models

### ActivatableModel and ActivatableQuerySet

Frequently objects need to have some kind of *active* flag, because deleting records is not an option.

Abstract model `ActivatableModel` defines `is_active` field for this purpose, which is `True` by default.

`ActivatableQuerySet` is a corresponding QuerySet that defines filters `active` and `inactive` for models which have `ActivatableModel` as parent.

```
class MyModel(ActivatableModel):
    ...

    objects = ActivatableQueryset.as_manager()
```

or:

```
class MyQueryset(ActivatableQueryset):
    ...


class MyModel(ActivatableModel):
    ...

    objects = MyQueryset.as_manager()
```

### CancellableModel and CancellableQuerySet

Sometimes there is a need to mark some objects as cancelled.

Abstract model `CancellableModel` defines field `is_cancelled`, which is `False` by default.

`CancellableQuerySet` is a corresponding QuerySet that defines filters `cancelled` and `not_cancelled` for models which have `CancellableModel` as parent.

```
class MyModel(CancellableModel):
    ...

    objects = CancellableQueryset.as_manager()
```

or:

```
class MyQueryset(CancellableQueryset):
    ...


class MyModel(CancellableModel):
    ...

    objects = MyQueryset.as_manager()
```

### CancellationModel and CancellationQuerySet

Sometimes there is a need to provide some additional information for cancelled objects.

Abstract model `CancellationModel` defines fields `cancelled_at`, `cancelled_by` and `cancellation_reason`, while `CancellationQuerySet` is a corresponding QuerySet that defines filters `cancelled`, `not_cancelled` and `cancelled_by`.

```
class MyModel(CancellationModel):
    ...

    objects = CancellationQueryset.as_manager()
```

or:

```
class MyQueryset(CancellationQueryset):
    ...


class MyModel(CancellationModel):
    ...

    objects = MyQueryset.as_manager()
```

### LockableModel and LockableQuerySet

Sometimes there is a need to mark some objects as locked (not available for further editing).

Abstract model `LockableModel` defines field `is_locked`, which is `False` by default.

`LockableQuerySet` is a corresponding QuerySet that defines filters `locked` and `unlocked` for models which have `LockableModel` as parent.

```
class MyModel(LockableModel):
    ...

    objects = LockableQueryset.as_manager()
```

or:

```
class MyQueryset(LockableQueryset):
    ...


class MyModel(LockableModel):
    ...

    objects = MyQueryset.as_manager()
```

### TimestampableModel

Sometimes there is a need to record when are objects created and last updated.

Abstract model `TimestampableModel` defines fields `created_at` and `updated_at` which store a timestamp when the model instance was created and last updated.

Timestamps are populated using `pre_save` signal timestampable. Unfortunately, creating and updating objects in bulk doesn't update created_by and modified_by fields, since `pre_save` is not called.

```
class MyModel(TimestampableModel):
    ...

```

### UserstampableModel and UserstampableQuerySet

Sometimes there is a need to record who has created and last updated an object.

Abstract model `UserstampableModel` defines fields `created_by` and `updated_by` for storing a `User` instance which created and last updated the model instance. Deletion of the referenced created_by and modified_by objects is protected.

`UserstampableQuerySet` is a corresponding QuerySet that defines filters `created_by` and `updated_by`.

```
class MyModel(UserstampableModel):
    ...

    objects = UserstampableQueryset.as_manager()
```

or:

```
class MyQueryset(UserstampableQueryset):
    ...


class MyModel(UserstampableModel):
    ...

    objects = MyQueryset.as_manager()
```

This abstract model uses `CurrentUserMiddleware` which must be added to `settings.MIDDLEWARE` after `django.contrib.auth.middleware.AuthenticationMiddleware`.


## Translations

Package comes with translations to:

- Croatian (hr)

To create translations for new language:

```bash
$ git clone git@gitlab.com:gs-django-modelplus.git
$ cd gs-django-modelplus
$ uv sync
$ uv run django-admin makemessages -l language_code
# edit django.po file for the new language
$ make compilemessages
# build will also automatically compile messages
$ uv build
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gs-django-modelplus",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "django, models",
    "author": null,
    "author_email": "Sandi \u0160aban <sandi.saban@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/99/26/e8d86fbe91f1aec992e8301da14615beab5bafed23748dfd38cee0b75dba/gs_django_modelplus-1.0.0.tar.gz",
    "platform": null,
    "description": "# gs-django-modelplus\n\nDjango application `modelplus` defines reusable abstract models that can be used to quickly and consistently add common fields and their functionalities to your models.\n\n\n## Installation\n\nIf using Astral's uv for virtual environment and project dependencies:\n\n```\n$ uv add gs-django-modelplus\n```\n\nOr, with pip in your virtual environment:\n\n```\n$ pip install gs-django-modelplus\n```\n\n\n## Quick setup\n\nAdd application to `settings.py`:\n\n```\nINSTALLED_APPS = [\n    ...\n    \"modelplus\",\n]\n```\n\nIf using abstract model `UserstampableModel`, `CurrentUserMiddleware` has be added to `settings.py` after `django.contrib.auth.middleware.AuthenticationMiddleware`:\n\n```\nMIDDLEWARE = [\n    ...\n    \"modelplus.middleware.CurrentUserMiddleware\",\n]\n```\n\n\n## Abstract models\n\n### ActivatableModel and ActivatableQuerySet\n\nFrequently objects need to have some kind of *active* flag, because deleting records is not an option.\n\nAbstract model `ActivatableModel` defines `is_active` field for this purpose, which is `True` by default.\n\n`ActivatableQuerySet` is a corresponding QuerySet that defines filters `active` and `inactive` for models which have `ActivatableModel` as parent.\n\n```\nclass MyModel(ActivatableModel):\n    ...\n\n    objects = ActivatableQueryset.as_manager()\n```\n\nor:\n\n```\nclass MyQueryset(ActivatableQueryset):\n    ...\n\n\nclass MyModel(ActivatableModel):\n    ...\n\n    objects = MyQueryset.as_manager()\n```\n\n### CancellableModel and CancellableQuerySet\n\nSometimes there is a need to mark some objects as cancelled.\n\nAbstract model `CancellableModel` defines field `is_cancelled`, which is `False` by default.\n\n`CancellableQuerySet` is a corresponding QuerySet that defines filters `cancelled` and `not_cancelled` for models which have `CancellableModel` as parent.\n\n```\nclass MyModel(CancellableModel):\n    ...\n\n    objects = CancellableQueryset.as_manager()\n```\n\nor:\n\n```\nclass MyQueryset(CancellableQueryset):\n    ...\n\n\nclass MyModel(CancellableModel):\n    ...\n\n    objects = MyQueryset.as_manager()\n```\n\n### CancellationModel and CancellationQuerySet\n\nSometimes there is a need to provide some additional information for cancelled objects.\n\nAbstract model `CancellationModel` defines fields `cancelled_at`, `cancelled_by` and `cancellation_reason`, while `CancellationQuerySet` is a corresponding QuerySet that defines filters `cancelled`, `not_cancelled` and `cancelled_by`.\n\n```\nclass MyModel(CancellationModel):\n    ...\n\n    objects = CancellationQueryset.as_manager()\n```\n\nor:\n\n```\nclass MyQueryset(CancellationQueryset):\n    ...\n\n\nclass MyModel(CancellationModel):\n    ...\n\n    objects = MyQueryset.as_manager()\n```\n\n### LockableModel and LockableQuerySet\n\nSometimes there is a need to mark some objects as locked (not available for further editing).\n\nAbstract model `LockableModel` defines field `is_locked`, which is `False` by default.\n\n`LockableQuerySet` is a corresponding QuerySet that defines filters `locked` and `unlocked` for models which have `LockableModel` as parent.\n\n```\nclass MyModel(LockableModel):\n    ...\n\n    objects = LockableQueryset.as_manager()\n```\n\nor:\n\n```\nclass MyQueryset(LockableQueryset):\n    ...\n\n\nclass MyModel(LockableModel):\n    ...\n\n    objects = MyQueryset.as_manager()\n```\n\n### TimestampableModel\n\nSometimes there is a need to record when are objects created and last updated.\n\nAbstract model `TimestampableModel` defines fields `created_at` and `updated_at` which store a timestamp when the model instance was created and last updated.\n\nTimestamps are populated using `pre_save` signal timestampable. Unfortunately, creating and updating objects in bulk doesn't update created_by and modified_by fields, since `pre_save` is not called.\n\n```\nclass MyModel(TimestampableModel):\n    ...\n\n```\n\n### UserstampableModel and UserstampableQuerySet\n\nSometimes there is a need to record who has created and last updated an object.\n\nAbstract model `UserstampableModel` defines fields `created_by` and `updated_by` for storing a `User` instance which created and last updated the model instance. Deletion of the referenced created_by and modified_by objects is protected.\n\n`UserstampableQuerySet` is a corresponding QuerySet that defines filters `created_by` and `updated_by`.\n\n```\nclass MyModel(UserstampableModel):\n    ...\n\n    objects = UserstampableQueryset.as_manager()\n```\n\nor:\n\n```\nclass MyQueryset(UserstampableQueryset):\n    ...\n\n\nclass MyModel(UserstampableModel):\n    ...\n\n    objects = MyQueryset.as_manager()\n```\n\nThis abstract model uses `CurrentUserMiddleware` which must be added to `settings.MIDDLEWARE` after `django.contrib.auth.middleware.AuthenticationMiddleware`.\n\n\n## Translations\n\nPackage comes with translations to:\n\n- Croatian (hr)\n\nTo create translations for new language:\n\n```bash\n$ git clone git@gitlab.com:gs-django-modelplus.git\n$ cd gs-django-modelplus\n$ uv sync\n$ uv run django-admin makemessages -l language_code\n# edit django.po file for the new language\n$ make compilemessages\n# build will also automatically compile messages\n$ uv build\n```\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2025 Sandi \u0160aban  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Reusable abstract django models",
    "version": "1.0.0",
    "project_urls": null,
    "split_keywords": [
        "django",
        " models"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ad530fcebb9b61356a925315174c1d25dce1c6fa4193a2c5c8b6db1aa0203372",
                "md5": "fc9571ce8a0c4c651240005dd4e7c930",
                "sha256": "e28219556ba75b3ae04e60949e117fc3f401a5779b26ef024e96b7a7dd40f1cc"
            },
            "downloads": -1,
            "filename": "gs_django_modelplus-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fc9571ce8a0c4c651240005dd4e7c930",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 9438,
            "upload_time": "2025-08-26T06:45:48",
            "upload_time_iso_8601": "2025-08-26T06:45:48.811565Z",
            "url": "https://files.pythonhosted.org/packages/ad/53/0fcebb9b61356a925315174c1d25dce1c6fa4193a2c5c8b6db1aa0203372/gs_django_modelplus-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9926e8d86fbe91f1aec992e8301da14615beab5bafed23748dfd38cee0b75dba",
                "md5": "c17f10c3f9cbf4896ba4b67eb9990148",
                "sha256": "583b286522e92d7cc3b57a202ff2b31e90f09b3e3403bc389673e082d6e4fcb5"
            },
            "downloads": -1,
            "filename": "gs_django_modelplus-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c17f10c3f9cbf4896ba4b67eb9990148",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 7905,
            "upload_time": "2025-08-26T06:45:49",
            "upload_time_iso_8601": "2025-08-26T06:45:49.870380Z",
            "url": "https://files.pythonhosted.org/packages/99/26/e8d86fbe91f1aec992e8301da14615beab5bafed23748dfd38cee0b75dba/gs_django_modelplus-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-26 06:45:49",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gs-django-modelplus"
}
        
Elapsed time: 0.98714s