这是我的方法:
from django.contrib.contenttypes.models import ContentTypefrom django.contrib.contenttypes import fieldsclass Photo(models.Model): picture = models.ImageField(null=True, upload_to='./images/') caption = models.CharField(_("Optional caption"),max_length=100,null=True, blank=True) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = fields.GenericForeignKey('content_type', 'object_id')class Article(models.Model): .... images = fields.GenericRelation(Photo)
您将添加类似
content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = fields.GenericForeignKey('content_type', 'object_id')
喜爱和
fields.GenericRelation(Faves)
到文章和演员表
contenttypes
docs
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)