Skip to content

About

Add custom fields to any Django model at runtime: validated, filterable with the ORM, and no schema changes.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

369 stars

Watchers

5 watching

Forks

Repository files navigation

Build Status codecov Python Version Django Version

Django EAV 2

Django EAV 2 stores extra, typed attributes for your Django models without changing their tables. Define an attribute once, then read, write, and filter it on any registered model as if it were a field. Administrators can add and change attributes at runtime, in the Django admin or in code, without a migration.

It is a fork of django-eav, which was itself derived from eav-django.

Read the documentation at https://django-eav2.readthedocs.io.

Install

pip install django-eav2

Add eav to INSTALLED_APPS, then run python manage.py migrate:

INSTALLED_APPS = [
    # ...
    "eav",
]

The package's tables use BigAutoField primary keys. To use UUIDs, set EAV2_PRIMARY_KEY_FIELD = "django.db.models.UUIDField" before the first migrate. See the configuration docs.

Quick start

Register a model, create an attribute, then store and query values:

import eav
from django.db import models
from eav.models import Attribute


class Supplier(models.Model):
    name = models.CharField(max_length=100)


eav.register(Supplier)

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

supplier = Supplier.objects.create(name="Acme", eav__city="London")
supplier.eav.city  # "London"

Supplier.objects.filter(eav__city="London")

Is EAV right for you?

EAV trades query speed and simplicity for flexibility. It suits open-ended, sparse, or user-defined properties, and is a poor fit for stable, known columns or performance-critical reporting. The concepts page explains the model, when to use it, when to avoid it, and the alternatives.

Contributing

See CONTRIBUTING.md. The project is part of Django Commons, and follows its code of conduct.

About

Add custom fields to any Django model at runtime: validated, filterable with the ORM, and no schema changes.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

369 stars

Watchers

5 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages