Django EAV 2 - EAV storage for modern Django
Find a file
2023-10-05 15:32:18 +01:00
.github feat: add support for Django 4.1 2023-02-10 09:59:54 -07:00
docs update links (#275) 2022-11-16 01:53:47 +02:00
eav fix: error on attribute creation 2023-09-07 16:49:22 +01:00
test_project feat: natural key handler added to models except value model 2023-09-06 16:54:16 +01:00
tests test: remove deprecated slug test 2022-08-12 14:45:30 -07:00
.editorconfig update links (#275) 2022-11-16 01:53:47 +02:00
.gitignore fixes https://github.com/jazzband/django-eav2/issues/163 (#164) 2022-02-08 18:13:12 -08:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate 2023-07-17 20:26:41 +00:00
.readthedocs.yml docs: update config file path 2022-08-12 18:19:47 -07:00
CHANGELOG.md fix: error on attribute creation 2023-09-07 16:49:22 +01:00
CODE_OF_CONDUCT.md Jazzband: Created local 'CODE_OF_CONDUCT.md' from remote 'CODE_OF_CONDUCT.md' 2021-10-21 14:35:01 +00:00
CONTRIBUTING.md update links (#275) 2022-11-16 01:53:47 +02:00
CONTRIBUTORS.md updating contrib 2021-04-23 16:15:19 -03:00
LICENSE update links (#275) 2022-11-16 01:53:47 +02:00
manage.py test: flatten test project 2021-07-04 08:58:33 -07:00
poetry.lock chore(deps): bump sphinx-rtd-theme from 1.2.2 to 1.3.0 2023-08-25 04:38:23 +00:00
pyproject.toml fix: error on attribute creation 2023-09-07 16:49:22 +01:00
README.md readme updated 2023-10-05 15:31:16 +01:00
setup.cfg style: ignore string over-use in migrations files 2023-02-22 08:08:59 -07:00

Build Status codecov Python Version Django Version Jazzband

Django EAV 2 - Entity-Attribute-Value storage for Django

Django EAV 2 is a fork of django-eav. You can find documentation here for more information.

What is new here ?

With this version of django eav, you can use an IntegerField or a UUIDField as the primary key for your eav models. You can also use the natural key for serialization instead of the primary key.

Installation

Install with pip

pip install django-eav2

Configuration

Add eav to INSTALLED_APPS in your settings.

INSTALLED_APPS = [
    ...
    'eav',
]

Add django.db.models.UUIDField or django.db.models.BigAutoField as value of PRIMARY_KEY_FIELD in your settings

PRIMARY_KEY_FIELD = "django.db.models.UUIDField" # as exemple

Note: Primary key mandatory modification field

If the primary key of eav models are to be modified (UUIDField -> BigAutoField, BigAutoField -> UUIDField) in the middle of the project when the migrations are already done, you have to change the value of PRIMARY_KEY_FIELD in your settings.

Step 1

Change the value of PRIMARY_KEY_FIELD into django.db.models.CharField in your settings.

PRIMARY_KEY_FIELD = "django.db.models.CharField"

Run the migrations

python manage.py makemigrations
python manage.py migrate
Step 2

Change the value of PRIMARY_KEY_FIELD into the desired value (django.db.models.BigAutoField or django.db.models.UUIDField) in your settings.

PRIMARY_KEY_FIELD = "django.db.models.BigAutoField" # as exemple

Run again the migrations.

 python manage.py makemigrations
 python manage.py migrate

Note: Django 2.2 Users

Since models.JSONField() isn't supported in Django 2.2, we use django-jsonfield-backport to provide JSONField functionality.

This requires adding django_jsonfield_backport to your INSTALLED_APPS as well.

INSTALLED_APPS = [
    ...
    'eav',
    'django_jsonfield_backport',
]

Getting started

Step 1. Register a model:

import eav
eav.register(Supplier)

or with decorators:

from eav.decorators import register_eav

@register_eav
class Supplier(models.Model):
    ...

Step 2. Create an attribute:

Attribute.objects.create(name='City', datatype=Attribute.TYPE_TEXT)

Step 3. Thats it! Youre ready to go:

supplier.eav.city = 'London'
supplier.save()

Supplier.objects.filter(eav__city='London')
# = <EavQuerySet [<Supplier: Supplier object (1)>]>

For futher information? Check out the django eav2 documentation.