小编Ton*_*ght的帖子

django-reversion和相关模型

我有以下models.py

class Contact(models.Model):
    pass

class Link(models.Model):
    pass

class Relationship(models.Model):
    # Documentation
    __doc__ = _(u'Stores a relationship between 2 contacts.')
    # Attributes
    from_contact = models.ForeignKey(Contact, related_name='from_contacts', verbose_name=_(u'first contact'), help_text=_(u'The first contact implicated by the relationship.'))
    link = models.ForeignKey(Link, related_name=u'relationships', verbose_name=_(u'relationship link'), help_text=_(u'The relationship link between both contacts.'))
    to_contact = models.ForeignKey(Contact, related_name='to_contacts', verbose_name=_(u'second contact'), help_text=_(u'The second contact implicated by the relationship.'))

    # Meta-data
    class Meta:
        verbose_name = u'Relationship'
        verbose_name_plural = u'Relationships'
        unique_together = ('from_contact', 'link', 'to_contact')
Run Code Online (Sandbox Code Playgroud)

使用Django的基于类的视图Revision Context Manager,我可以随时创建修订版本,在2个联系人之间创建新的关系

# …
Run Code Online (Sandbox Code Playgroud)

django django-reversion

18
推荐指数
1
解决办法
1676
查看次数

标签 统计

django ×1

django-reversion ×1