为Django共享
django-shares的Python项目详细描述
注意:这还不稳定,可能会改变请不要在生产中使用,直到1.0版本
django共享
django sharing是一个为django编写的python共享模块,用于处理对象共享不要克隆。不稳定
示例
基本示例:
from django.contrib.contenttypes import generic from django.db import models from django_sharing.models import Share class Car(models.Model): """A model that will be shared.""" # Add the reverse relation since the shared object is a generic object. shares = generic.GenericRelation(Share)
扩展共享模型:
from django.contrib.contenttypes import generic from django.db import models from django_sharing.models import AbstractShare class CarShare(AbstractShare): """Extending the share model to add additional attributes.""" day = models.CharField(max_length=50) class Car(models.Model): """A model that will be shared.""" # Add the reverse relation since the shared object is a generic object. shares = generic.GenericRelation(CarShare)
运行测试
在manage.py文件所在的tests目录中,运行以下命令:
python manage.py test