Package: django-model-reviews
django-model-reviewsEasy moderation of changes made to models.What is this forThis is a reusable library (django app) that can be used and re-used to implement reviews/moderation for Django models that need it.Therefore, things start with a model that needs the ability to be reviewed or moderated.  Once this model is set up to work withdjango-model-reviews, every time an object is created or updated a request for review/moderation will be created.When the model objects that need to be reviewed/moderated are created, a few things happen:A ModelReview object is created and linked to the object that needs moderationOne or more Reviewer objects are created.  Reviewers are the users who are allowed to do the actual review/moderation.  This is determined by theset_reviewers_functionoption (see below).An email is sent to each reviewer, asking them to do the review.The next step would be that one of the reviewers logs in, and does the actual moderation/review.  This library includes a Django view and form than enables this.When this is done, an email is sent nn email is sent to the user who requested the review.  This user is determined by using theset_user_functionoption (see below).Finally, any side effects arising from the review are propagated.  Side effects are configurable via theside_effect_functionoption (see below).And with that, the review process is completed.InstallationInstall the app:pip install django-model-reviewsAddmodel_reviewstoINSTALLED_APPS.Each model review can optionally have comments.  To enable this, also adddjango_commentsto installed apps.  Make sure to adddjango_commentsaftermodel_reviews.INSTALLED_APPS=[# the usual django stuff'model_reviews','django_comments',]Runmanage.py migrateso that Django will create the model_review tables.Add the model_reviews app’s URLs to your project’s urls.py:urlpatterns=[# ...path("reviews/",include('model_reviews.urls')),# ...]Optionally, also installdjango_commentsHow to useSet up modelsEach model that needs a review step will need to be set up by extendingAbstractReview.This will result in the model having two new fields:review_reason: a text field that a user can fill in when requesting a reviewreview_status: can be one of Pending, Approved or Rejected (defaults to Pending)review_date: the date that the review was done (defaults to None)When creating you model class, you can set further options like so:monitored_fields: a list of fields that should trigger a review.  That is, if these fields change a review will be neededside_effect_function: path to function that will be run after successful reviewset_reviewers_function: path to function that will be used to determine reviewersset_user_function: path to function that will be used to determine the user for a review objectrequest_for_review_function: path to function that will be used to send email to reviewersreview_complete_notify_function: path to function that will be used to send email to user after reviewYou can also set email options as such:review_request_email_subject: email subject to request a review.  Default isThere has been a new request that needs your attention.review_request_email_body: email body to request a review.  Default isNew Request For Approvalreview_complete_email_subject: subject of email sent after review is complete.  Default isYour request has been processedreview_complete_email_body: body of email sent after review is complete.  Default isYour request has been processed, please log in to view the status.email_template: email template to use.  Default isgenericemail_template_path: path to email template to use.  Default ismodel_reviews/emailBelow is an example model class definition:fromdjango.contrib.auth.modelsimportUserfromdjango.dbimportmodelsfrommodel_reviews.modelsimportAbstractReviewclassResearchPaper(AbstractReview):"""Model definition for important scientific research papers.In this example this is a model which needs to be reviewed."""name=models.CharField(max_length=100)# ... other important fields would go here# this can be used as the user who is "requesting a view"user=models.ForeignKey(User,on_delete=models.CASCADE,null=True,default=None,blank=True)# options# List of fields that need moderation/reviewmonitored_fields:List[str]=["review_status","review_date","name"]# path to function that will be run after successful reviewside_effect_function:Optional[str]="your_app.some_path.side_effect_function"# path to function that will be used to determine reviewersset_reviewers_function:Optional[str]="your_app.some_path.set_reviewers_function"# path to function that will be used to determine the user for a review objectset_user_function:Optional[str]="model_reviews.side_effects.set_review_user"# path to function that will be used to send email to reviewersrequest_for_review_function:Optional[str]="model_reviews.emails.send_single_request_for_review"# path to function that will be used to send email to user after reviewreview_complete_notify_function:Optional[str]="model_reviews.emails.send_review_complete_notice"Set up templatesFor best results, you would want tooverridethemodel_reviews/modelreview_detail.html(you can view ourstarter template in the templates directory)   template in your own Django app.You should modify this template to look exactly as you wish, and include all the information needed for a user to perform a review.  The template receives a context variables namedobjectwhich is the ModelReview instance in question.object.content_objectin turn refers to the instance of the model being reviewed.Set up emailsYou likely will want to heavily customize the emails being sent.  The best way to do this is to change the templates being used to send emails.  The default templates used are in this directorymodel_reviews/templates/model_reviews/email.  To change this, do the following:Copy the templates in the email directory to a directory of your choiceModify theemail_templateandemail_template_pathoptions on your model class to point to the new templates from step just 1 above.Modify your custom email templates to your heart's content.You can also optionally change therequest_for_review_functionandreview_complete_notify_functionto modify the emails further.  This functions simply specify what is included in the emails sent, and you can provide your own functions to configure this.  The default functions are here:model_reviews/emails.pySet up commentsYou can optionally set up django_comments (formerly of django.contrib fame) to add comment functionality in your reviews.  Please see thedjango_comments documentationfor further guidance on how to install this library.The starter template over atmodel_reviews/modelreview_detail.htmlincludes commented out code that would add our own starter django_comments integration which live atmodel_reviews/templates/comments.ContributionClone this repoRun:pip install -r requirements/dev.txtRun:pre-commit installTestsClone this repoRun:pip install -r requirements/dev.txtRun:toxInspirationdjango-approval