在提交到数据库之前存储数据,等待管理员的批准

时间:2021-06-17 19:35:11

My issue is the following:

我的问题是:

I'm building a mobile app using Ionic framework, so the front end is essentially a single page AngularJS app. I'm using Django Rest framework as the backend.

我正在使用Ionic framework构建一个移动应用,所以前端实际上是一个单页面的AngularJS应用。我使用Django Rest框架作为后端。

In the application, an employee should be able to suggest updates, deletes, or additions to database models. In my schema, there is a "Contact person" model (which has fields like first_name, last_name, phone_number, etc.), a "GPS Address model" (which has fields like street_name, street_num, city, etc.) and an overarching "Delivery stop" model to which virtually all of the other models relate.

在应用程序中,员工应该能够建议对数据库模型进行更新、删除或添加。在我的模式中,有一个“联系人”模型(它有first_name、last_name、phone_number等字段)、一个“GPS地址模型”(它有street_name、street_num、city等字段)和一个包罗万象的“交付停止”模型,几乎所有其他模型都与之相关。

What I need to implement is a system whereby an employee can suggest an edit to an existing object, say a Contact (id: 45, first_name: 'John', phone_number: "435-0000") which has a FK relationship to a Delivery Stop (id: 20, title: "Stop and Shop", notes: "closes at 0600"). The employee wants to update the phone number to "435-0001". But the update shouldn't be committed to the database until a manager has reviewed the update and approved, or edited the update then approved.

我需要实现的是一个系统,在该系统中,员工可以建议对现有对象进行编辑,比如联系人(id: 45, first_name: 'John', phone_number: "435-0000"),该系统与交付停止(id: 20,标题:"Stop and Shop",注意:" 0600关闭")。该员工希望将电话号码更新为“435-0001”。但是更新不应该提交给数据库,直到管理员检查了更新并批准,或者编辑了更新并批准。

I have a few ideas about how I might do this, but none of them seem as easy as I think it could be. Does anyone have any suggestions about best practices in this situation?

我对如何做到这一点有一些想法,但没有一个像我认为的那样容易。有人对这种情况下的最佳实践有什么建议吗?

The application will also include a special manager interface where they can few all suggested updates/edits and approve/reject them. The client side essentially functions with the Delivery Stop as the primary object, which shows all related items in a tabbed interface (Contacts, Gps addresses, etc.) And each time an edit is suggested by an employee, the appropriate manager will receive an email notification.

应用程序还将包含一个特殊的管理器接口,在该接口中,可以几乎不进行任何建议的更新/编辑和批准/拒绝。客户端本质上是作为主要对象的传递停止,它显示了选项卡界面中的所有相关项(联系人、Gps地址等),并且每一次编辑建议由雇员提出,相应的管理人员将收到一封电子邮件通知。

Any suggestions are much appreciated.

如有任何建议,我们将不胜感激。

1 个解决方案

#1


2  

If this were my project, I'd save all changes to the same database table but I'd mark a field called "WaitingForApproval" as True. Then you can create a page for admins showing all the items waiting to be approved and they can either approve or deny them.

如果这是我的项目,我会将所有更改保存到同一个数据库表中,但我会将一个名为“WaitingForApproval”的字段标记为True。然后,您可以为管理员创建一个页面,显示所有等待批准的项目,他们可以批准或拒绝它们。

When denied, you can either delete that record or mark a field called "Deleted" as true and make sure not to ever show that record unless somebody specifically wants to see deleted records.

当被拒绝时,您可以删除该记录或将一个名为“已删除”的字段标记为true,并确保永远不会显示该记录,除非有人特别希望看到已删除的记录。

Anytime you pull data from the database, you'll want to filter based on WaitingForApproval being true or false (usually false, unless it's specifically for the admin approval page). This way, you can keep pending changes in the same table without cluttering up the rest of the application.

每当您从数据库中提取数据时,您都希望基于等待审批是真还是假(通常是假的,除非是专门针对admin approval页面)进行过滤。通过这种方式,您可以在相同的表中保留挂起的更改,而不需要占用应用程序的其余部分。

Or if you already have a lot of queries written in the app that you don't want to change, you can just save these pending changes into a different but identical database table. When an admin approves it, your back-end code will just copy the data from the PendingChanges table to the Main table.

或者,如果您已经在应用程序中编写了许多不希望更改的查询,您可以将这些挂起的更改保存到另一个不同但相同的数据库表中。当管理员批准时,后端代码将从PendingChanges表将数据复制到主表。

#1


2  

If this were my project, I'd save all changes to the same database table but I'd mark a field called "WaitingForApproval" as True. Then you can create a page for admins showing all the items waiting to be approved and they can either approve or deny them.

如果这是我的项目,我会将所有更改保存到同一个数据库表中,但我会将一个名为“WaitingForApproval”的字段标记为True。然后,您可以为管理员创建一个页面,显示所有等待批准的项目,他们可以批准或拒绝它们。

When denied, you can either delete that record or mark a field called "Deleted" as true and make sure not to ever show that record unless somebody specifically wants to see deleted records.

当被拒绝时,您可以删除该记录或将一个名为“已删除”的字段标记为true,并确保永远不会显示该记录,除非有人特别希望看到已删除的记录。

Anytime you pull data from the database, you'll want to filter based on WaitingForApproval being true or false (usually false, unless it's specifically for the admin approval page). This way, you can keep pending changes in the same table without cluttering up the rest of the application.

每当您从数据库中提取数据时,您都希望基于等待审批是真还是假(通常是假的,除非是专门针对admin approval页面)进行过滤。通过这种方式,您可以在相同的表中保留挂起的更改,而不需要占用应用程序的其余部分。

Or if you already have a lot of queries written in the app that you don't want to change, you can just save these pending changes into a different but identical database table. When an admin approves it, your back-end code will just copy the data from the PendingChanges table to the Main table.

或者,如果您已经在应用程序中编写了许多不希望更改的查询,您可以将这些挂起的更改保存到另一个不同但相同的数据库表中。当管理员批准时,后端代码将从PendingChanges表将数据复制到主表。