mirror of
https://github.com/jazzband/django-eav2.git
synced 2026-04-13 19:51:09 +00:00
68 lines
2.1 KiB
Markdown
68 lines
2.1 KiB
Markdown
|
||
[](https://travis-ci.org/makimo/django-eav2)
|
||
[](https://coveralls.io/github/makimo/django-eav2?branch=master)
|
||
[](https://www.codacy.com/app/IwoHerka/django-eav2?utm_source=github.com&utm_medium=referral&utm_content=makimo/django-eav2&utm_campaign=Badge_Grade)
|
||
[](https://codeclimate.com/github/makimo/django-eav2/maintainability)
|
||

|
||

|
||
|
||
## Django EAV 2 - Entity-Attribute-Value storage for Django
|
||
|
||
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>.
|
||
|
||
## Installation
|
||
You can install **django-eav2** from three sources:
|
||
```bash
|
||
# From PyPI via pip
|
||
pip install django-eav2
|
||
|
||
# From source via pip
|
||
pip install git+https://github.com/makimo/django-eav2@master
|
||
|
||
# From source via setuptools
|
||
git clone git@github.com:makimo/django-eav2.git
|
||
cd django-eav2
|
||
python setup.py install
|
||
|
||
# To uninstall:
|
||
python setup.py install --record files.txt
|
||
rm $(cat files.txt)
|
||
```
|
||
|
||
## Getting started
|
||
|
||
**Step 1.** Register a model:
|
||
|
||
```python
|
||
import eav
|
||
eav.register(Supplier)
|
||
```
|
||
|
||
or with decorators:
|
||
|
||
```python
|
||
from eav.decorators import register_eav
|
||
|
||
@register_eav
|
||
class Supplier(models.Model):
|
||
...
|
||
```
|
||
|
||
**Step 2.** Create an attribute:
|
||
|
||
```python
|
||
Attribute.objects.create(name='City', datatype=Attribute.TYPE_TEXT)
|
||
```
|
||
|
||
**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)>]>
|
||
```
|
||
|
||
### What next? Check out <a href="https://django-eav-2.readthedocs.io/en/improvement-docs/">documentation</a>.
|