models.py 文件源码

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

项目:cep-web-service 作者: IuryAlves 项目源码 文件源码
def save_document(cls, zip_code, address, neighborhood, city, state):
        """
        Create or update a document
        returns True if created and False if only updated
        Update condition is based on zipcode. If zipcode already exists in db
        the the document is only updated. Otherwise the document is created
        """
        try:
            object_ = cls.objects.get(zip_code=zip_code)
            object_.update(
                address=address,
                neighborhood=neighborhood,
                city=city,
                state=state
            )
            return False
        except DoesNotExist:
            cls(
                zip_code=zip_code,
                address=address,
                neighborhood=neighborhood,
                city=city,
                state=state).save()
            return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号