Django Iphone 同步
我正在编写 django 应用程序和 Iphone 应用程序,我需要使它们保持同步。 用户可以在 Web 应用程序和 iPhone 应用程序中删除、更新和创建新对象。 当他们使用 iPhone 上网时,两个应用程序必须同步。 有简单的方法可以做到这一点吗?
谢谢,
华金
I am writting a django app and Iphone app, I need to keep them in sync.
Users can delete, update and create new objects in the web app, and in the iphone app.
When they get online with the iphone both app must be in sync.
Is there simple way to do this?
Thanks,
Joaquin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说:没有简单的方法。但我将概述一种方法。
如果您不关心更改被覆盖:保留每条记录的最新更改的时间戳以及每次同步的时间戳。同步时,您将获得自上次同步以来 iPhone 上的所有更新以及服务器上的所有更新的列表。如果该记录的 iPhone 时间戳比服务器时间戳新,则您可以从 iPhone 写入服务器,反之亦然。
但你可能会关心。假设您编辑了一条名为“星期五在哪里见面”的便笺。一开始是空的。现在,您在电话中写下了“我的房子”。十分钟后,您的朋友在服务器上编辑了同一条注释并写道:“餐馆。”谁胜出? Stack Overflow 无法为您解答;它是特定于应用程序的。
好的,所以修改上面的方法:如果自上次同步以来,服务器版本的记录和本地版本都被编辑过,那么你必须询问用户该怎么做。这就是基本算法。
如果您非常关心更改不被覆盖,以至于您想要将更改合并到同一文档中的不同位置,那么您的系统将开始接近 Subversion 或 Git 等版本控制系统的复杂性。一点也不简单。
In general: There's no simple way. But I'll outline an approach.
If you don't care about changes being overwritten: Keep a timestamp of the most recent change to each record, and a timestamp of each sync. When syncing, you get a list of all updates on the iPhone since the last sync, and all updates on the server. You write from the iPhone to the server if the iPhone timestamp for that record is newer than the server one, and vice versa.
But you probably care. Say you've edited a note called "Where to meet up on Friday." It started out empty. Now, on the phone, you've written, "My house." Ten minutes later, your friend edits the same note on the server and writes, "The diner." Who wins out? Stack Overflow can't answer that for you; it's application-specific.
OK, so modify the approach above: if both the server version of a record and the local version have been edited since the last sync, then you have to ask the user what to do. That's the basic algorithm.
If you care a lot about changes not being overwritten, to the point that you want to merge changes to different places in the same documents, then your system will begin to approach the complexity of version control systems like Subversion or Git. Not at all simple.
没有内置的方法可以做到这一点。你需要保留一个服务器数据存储,以及 iPhone 上的本地数据存储,并且在线时,手动检查差异,并查看应该在服务器和 iPhone 端执行哪些操作(删除、更新等)。
同步通常很困难。我建议你开始布局服务器和iPhone数据存储,并思考它们如何关联,以及服务器或iPhone如何知道其对应记录的状态,从而使它们保持同步。
There's no built in way to do this. You need to keep a server data store, and a local data store on the iPhone, and when online, check the differences manually, and see what action you should take on the server and the iPhone side (delete, update, etc.).
Sync is usually hard. I suggest you start laying out the server and iPhone data stores, and think how they relate, and how can the server or the iPhone know the status of their counterpart record, so to keep them in sync.