2018-06-29 12:33:06 +00:00
|
|
|
|
|
2018-06-01 14:15:07 +00:00
|
|
|
|
[](https://travis-ci.org/makimo/django-eav2)
|
2018-06-01 15:19:49 +00:00
|
|
|
|
[](https://coveralls.io/github/makimo/django-eav2?branch=master)
|
2018-06-04 11:09:38 +00:00
|
|
|
|
[](https://www.codacy.com/app/IwoHerka/django-eav2?utm_source=github.com&utm_medium=referral&utm_content=makimo/django-eav2&utm_campaign=Badge_Grade)
|
2018-06-03 13:14:15 +00:00
|
|
|
|
[](https://codeclimate.com/github/makimo/django-eav2/maintainability)
|
2018-06-08 16:15:26 +00:00
|
|
|
|

|
|
|
|
|
|

|
2018-06-01 14:15:07 +00:00
|
|
|
|
|
2018-06-29 12:33:06 +00:00
|
|
|
|
## Django EAV 2 - Entity-Attribute-Value storage for Django
|
2010-09-28 13:39:57 +00:00
|
|
|
|
|
2018-07-23 16:22:46 +00:00
|
|
|
|
Django EAV 2 is a fork of django-eav (which itself was derived from eav-django).
|
|
|
|
|
|
You can find documentation <a href="https://django-eav-2.rtfd.io">here</a>.
|
2010-09-28 13:39:57 +00:00
|
|
|
|
|
2018-06-29 12:33:06 +00:00
|
|
|
|
## Installation
|
|
|
|
|
|
You can install **django-eav2** from three sources:
|
|
|
|
|
|
```bash
|
|
|
|
|
|
# From PyPI via pip
|
|
|
|
|
|
pip install django-eav2
|
2018-06-01 12:29:17 +00:00
|
|
|
|
|
2018-06-29 12:33:06 +00:00
|
|
|
|
# From source via pip
|
|
|
|
|
|
pip install git+https://github.com/makimo/django-eav2@master
|
2018-06-06 23:02:04 +00:00
|
|
|
|
|
2018-06-29 12:33:06 +00:00
|
|
|
|
# From source via setuptools
|
|
|
|
|
|
git clone git@github.com:makimo/django-eav2.git
|
|
|
|
|
|
cd django-eav2
|
|
|
|
|
|
python setup.py install
|
2018-06-06 23:02:04 +00:00
|
|
|
|
|
2018-06-29 12:33:06 +00:00
|
|
|
|
# To uninstall:
|
|
|
|
|
|
python setup.py install --record files.txt
|
|
|
|
|
|
rm $(cat files.txt)
|
2018-06-06 23:02:04 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2018-06-29 12:33:06 +00:00
|
|
|
|
## Getting started
|
2018-06-06 23:02:04 +00:00
|
|
|
|
|
2018-06-29 12:33:06 +00:00
|
|
|
|
**Step 1.** Register a model:
|
|
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
|
import eav
|
|
|
|
|
|
eav.register(Supplier)
|
2018-06-06 23:02:04 +00:00
|
|
|
|
```
|
2018-06-29 12:33:06 +00:00
|
|
|
|
|
|
|
|
|
|
or with decorators:
|
|
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
|
from eav.decorators import register_eav
|
|
|
|
|
|
|
|
|
|
|
|
@register_eav
|
|
|
|
|
|
class Supplier(models.Model):
|
|
|
|
|
|
...
|
2018-06-06 23:02:04 +00:00
|
|
|
|
```
|
2018-06-29 12:33:06 +00:00
|
|
|
|
|
|
|
|
|
|
**Step 2.** Create an attribute:
|
|
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
|
Attribute.objects.create(name='City', datatype=Attribute.TYPE_TEXT)
|
2018-06-06 23:02:04 +00:00
|
|
|
|
```
|
2018-06-29 12:33:06 +00:00
|
|
|
|
|
|
|
|
|
|
**Step 3.** That’s it! You’re ready to go:
|
|
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
|
supplier.eav.city = 'London'
|
|
|
|
|
|
supplier.save()
|
|
|
|
|
|
|
|
|
|
|
|
Supplier.objects.filter(eav__city='London')
|
|
|
|
|
|
# = <EavQuerySet [<Supplier: Supplier object (1)>]>
|
2018-06-06 23:02:04 +00:00
|
|
|
|
```
|
2018-06-29 12:33:06 +00:00
|
|
|
|
|
2018-07-11 11:18:07 +00:00
|
|
|
|
### What next? Check out <a href="https://django-eav-2.readthedocs.io/en/improvement-docs/">documentation</a>.
|