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
评论列表
文章目录