Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup admin approval a model's edits

I need a system where a regular user can edit a model but the edits don't actually happen until they are approved by an administrator. I found a gem called paper_trail that does had model versioning but doesn't support specifically what I want to do. I'm wondering how other people have handled this problem. I should add that there are also associations that I would like to be able for the user to edit at the same time. They aren't very complicated, for example one is aliases.

The more complicated part maybe be the case where multiple users edit the same model and trying to do some sort of merge.

like image 760
hadees Avatar asked Jun 30 '11 23:06

hadees


People also ask

How to register models in admin in Django?

from django. contrib import admin # Register your models here. Register the models by copying the following text into the bottom of the file. This code imports the models and then calls admin.

What is admin panel in Django?

One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. The admin's recommended use is limited to an organization's internal management tool.

What is list_ display in Django?

It provides a simple UI for creating, editing and deleting data defined with the Django ORM. In this article we are going to enable the admin user interface for a simple model and customize it from a simple list view to a more user friendly table like interface.


1 Answers

One approach would be to do versioning with version approval.

Every edit creates a new version of the model object and its associations. At any one time there is only one "current" version of any model object (and it's representation in the database).

If two users submit two separate edits, these would create two "pending" versions.

An admin would approve edits by moving the current version to the new "pending" version. Merges could be accomplished as well, but that could be very domain specific, and could result in conflicts, so keeping separate versions would be smart anyways.

There are a few ways to accomplish this, and the best would depend on the dynamics of the situation.

I'd recommend looking at how Git works and trying to model your system after that. Some sort of pointer to your HEAD model object with a revision history and the ability to move HEAD to different revisions. Merging could also work similar to Git.

Hope that helps.

like image 146
jesse reiss Avatar answered Oct 06 '22 20:10

jesse reiss