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:
check the documentation for more examples and an in-depth description of the app (or keep reading for the 30 second version).
what it doesthe purpose of this project is to allow you to create database-level relationships between various objects using a consistent api.
example appbundled 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.
quick overviewsay 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 ("")>]Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution File detailsDetails for the file django-generic-m2m-0.3.1.tar.gz
.
88a181b5d4ed1140a7a2957dac3de255fc7cbdb6806238ddf8f79f75b84858ec
MD5 4c0210c0f38242aad1a90a67c6f783c1
BLAKE2b-256 f787ea20f90aab82e957251a03a90565be27857c3d2ca2292f0c344c364176c9
See more details on using hashes here.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4