https://github.com/20tab/twentytab-model-to-bidimensional
A django app that returns a bidimensional representation of a given model and queryset following foreign keys recursively
https://github.com/20tab/twentytab-model-to-bidimensional
Last synced: about 1 year ago
JSON representation
A django app that returns a bidimensional representation of a given model and queryset following foreign keys recursively
- Host: GitHub
- URL: https://github.com/20tab/twentytab-model-to-bidimensional
- Owner: 20tab
- License: mit
- Created: 2014-06-04T11:33:04.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-06-04T15:58:42.000Z (about 12 years ago)
- Last Synced: 2025-03-05T11:06:17.073Z (over 1 year ago)
- Language: Python
- Size: 164 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
twentytab-model-to-bidimensional
================================
A django app that returns a bidimensional representation of a given model and queryset following foreign keys recursively
**It doesn't work with many-to-many fields yet**
## Installation
Use the following command: pip install twentytab-model-to-bidimensional
## Usage
```py
from django.db import models
class Foo(models.Model):
name = models.CharField(max_length=250)
class Bar(models.Model):
foo = models.ForeignKey(Foo)
name = models.CharField(max_length=250)
```
```py
>>> from bidimensional import Bidimensional
>>> from myapp.models import Bar
>>> b = Bidimensional(Bar, depth=-1, queryset=Bar.objects.all())
>>> b.headers()
[u'id', u'name', u'foo__id', u'foo__name']
>>> b.items()
[{u'foo__id': 1, u'id': 1, u'foo__name': u'foo 1', u'name': u'bar 1'}, {u'foo__id': 2, u'id': 2, u'foo__name': u'foo 2', u'name': u'bar 2'}]
```
The results can be used to create a table like this example:
