[Fixed]-Django: Update template – notify admin

1👍

✅

Firstly, don’t allow your users to login to the admin, it’s not its goal:

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. It’s not intended for building your entire front end around.

Django Admin Official Reference

Considering that the admin is only restricted to “trusted users”, there is no need to validate their input.

You should rather create a form on your front-end (on the user’s profile space for instance).

To validate their input in this form you have several options. The simplest is probably to create a ModerationModel which would look like this:

class ModerationModel(models.Model):

    STATUS_CHOICES = [
        ('pending', _("Pending"),
        ('accepted', _("Accepted"),
        ('rejected', _("Rejected"),
    ]

    submitter = models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE)
    submitter_ip = models.GenericIPAddressField()
    date_submitted = models.DateTimeField(auto_now_add=True)
    status = models.CharField(max_length=20, choices=STATUS_CHOICES)
    form_class = models.CharField(
        max_length=100,
        help_text=_(
            "Python dotted path to the Form class. Example: "
            "myapp.forms.UserBiographyForm"
        ),
    )
    form_data = models.TextField(
        help_text=_(
            "Serialized form data"
        ),
    )

When the form is submitted, rather than calling the form.save() method, you will call a custom methods that creates a ModerationModel instance containing the serialized form data. You will then be able to unserialize the form data, rebuild the form instance and save it once you validated it.

Other solutions might be to use third party apps such as django-simple-history that enables you to keep track of changes made to model instances and revert the changes.

Leave a comment