This seems to do the job of the EAV tables. Besides being EAV, is there room for improvement? Maybe there is something obvious, but how about indexing certain columns?

from django.db import models

class Entity(models.Model):
    entity_id = models.AutoField(primary_key=True)
    entity = models.CharField(max_length=100)

class Attribute(models.Model):
    attribute_id = models.AutoField(primary_key=True)
    entity_id = models.ForeignKey(Entity)
    value = models.CharField(max_length=100)

class EntityTableAbstract(models.Model):
    class Meta:
        abstract = True

    entity_id = models.ForeignKey(Entity)
    attribute_id = models.ForeignKey(Attribute)

class EntityVarchar(EntityTableAbstract):
    value = models.TextField()

class EntityInteger(EntityTableAbstract):
    value = models.IntegerField()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.