• Stars
    star
    153
  • Rank 243,368 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

relate anything to anything

django-generic-m2m

relate anything to anything. the image below is a screenshot of the example app and shows a blog post that has been "related" to 2 "Place" models and a "City" model:

http://media.charlesleifer.com/blog/photos/genericm2m-tagging.png

check the documentation for more examples and an in-depth description of the app (or keep reading for the 30 second version).

what it does

the purpose of this project is to allow you to create database-level relationships between various objects using a consistent api.

example app

bundled with the source code is an example app which shows how generic-m2m can be used to create "tags" between models. it uses nathanborror's basic apps with django-completion (shameless plug) to allow users to "autocomplete" various relationships between models, so if I'm a user and want to create a new blog post I can tag it with relationships to objects representing a city, a place, a funny photo of a cat, etc.

http://media.charlesleifer.com/blog/photos/generic-m2m-rel-objs.png

quick overview

say you have a couple models:

class Food(models.Model):
    name = models.CharField(max_length=255)

    related = RelatedObjectsDescriptor()

    def __unicode__(self):
        return self.name


class Beverage(models.Model):
    name = models.CharField(max_length=255)

    related = RelatedObjectsDescriptor()

    def __unicode__(self):
        return self.name

Here's a sample interactive interpreter session to show the basic API:

>>> pizza = Food.objects.create(name='pizza')
>>> pepperoni = Food.objects.create(name='pepperoni')
>>> beer = Beverage.objects.create(name='beer')
>>> soda = Beverage.objects.create(name='soda')

>>> pizza.related.connect(pepperoni)
<RelatedObject: pizza related to pepperoni ("")>

>>> pizza.related.connect(beer)
<RelatedObject: pizza related to beer ("")>

>>> pepperoni.related.related_to()
[<RelatedObject: pizza related to pepperoni ("")>]

>>> pizza.related.all()
[<RelatedObject: pizza related to beer ("")>, <RelatedObject: pizza related to pepperoni ("")>]

>>> pizza.related.all().generic_objects()
[<Beverage: beer>, <Food: pepperoni>]

>>> Food.related.all()
[<RelatedObject: pizza related to beer ("")>, <RelatedObject: pizza related to pepperoni ("")>]

More Repositories

1

peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
Python
11,103
star
2

huey

a little task queue for python
Python
5,154
star
3

sqlite-web

Web-based SQLite database browser written in Python
Python
3,359
star
4

walrus

Lightweight Python utilities for working with Redis
Python
1,149
star
5

flask-peewee

flask integration for peewee, including admin, authentication, rest api and more
Python
776
star
6

micawber

a small library for extracting rich content from urls
Python
632
star
7

unqlite-python

Python bindings for the UnQLite embedded NoSQL database
C
389
star
8

django-relationships

Descriptive relationships between auth.users (think facebook friends and twitter followers, plus more)
Python
369
star
9

scout

RESTful search server written in Python, powered by SQLite.
Python
299
star
10

pysqlite3

SQLite3 DB-API 2.0 driver from Python 3, packaged separately, with improvements
C
184
star
11

irc

tinkering with a made-from-scratch irc library in python
Python
179
star
12

simpledb

miniature redis-like server implemented in Python
Python
138
star
13

python-lsm-db

Python bindings for the SQLite4 LSM database.
C
129
star
14

vedis-python

Python bindings for the Vedis embedded NoSQL database
C
125
star
15

wtf-peewee

WTForms integration for peewee
Python
111
star
16

sqlcipher3

Python 3 bindings for SQLCipher
C
85
star
17

sophy

Fast Python bindings to Sophia Database
C
80
star
18

django-generic-aggregation

annotate() and aggregate() for generically-related data.
Python
72
star
19

beefish

simple file encryption with pycrypto
Python
67
star
20

ucache

gametight lightweight caching library for python
Python
65
star
21

chrome-extensions

Personal collection of chrome extensions
JavaScript
61
star
22

sqlite-vtfunc

Implement SQLite table-valued functions with Python
Cython
58
star
23

sweepea

Fast, lightweight Python database toolkit for SQLite, built with Cython.
Cython
42
star
24

dot-theme

dotfile templating tools
Python
31
star
25

greendb

server frontend for lmdb
Python
25
star
26

kvkit

dank key/value store high-level APIs
Python
18
star
27

kt

Fast Python client for KyotoTycoon
Python
18
star
28

ukt

Kyoto Tycoon client library for Python.
Python
11
star
29

sqlite3-bloomfilter

Bloomfilter for SQLite3
C
6
star