models.py 文件源码

python
阅读 15 收藏 0 点赞 0 评论 0

项目:timestrap 作者: overshard 项目源码 文件源码
def add_current_site(sender, instance, **kwargs):
    """
    Add the current site to a model's sites property after a save. This is
    required in post save because ManyToManyField fields require an existing
    key.

    TODO: Don't run this on *every* post_save.
    """
    if hasattr(instance, 'sites'):
        if not instance.sites.all():
            instance.sites.set(Site.objects.filter(id=current_site_id()))
            instance.save()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号