From 05b9acbd0ddc97198729ade0f0fd4cd1c3788643 Mon Sep 17 00:00:00 2001 From: Arpith Muddi Date: Mon, 24 Apr 2023 11:57:43 +0200 Subject: [PATCH 1/2] Load .env file --- vidura/settings.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vidura/settings.py b/vidura/settings.py index f98ad6d..1a4fbf0 100644 --- a/vidura/settings.py +++ b/vidura/settings.py @@ -13,6 +13,10 @@ from pathlib import Path import os +# load ENV and DJANGO_SETTINGS_MODULE from .env file +from dotenv import load_dotenv +load_dotenv() + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent From 81aa436a93fa7c7dfa32805ea291ba79d2548e76 Mon Sep 17 00:00:00 2001 From: Arpith Muddi Date: Mon, 24 Apr 2023 15:03:01 +0200 Subject: [PATCH 2/2] Implement django revisions --- promptbook/admin.py | 6 +++++- promptbook/models.py | 3 ++- promptbook/views.py | 2 +- requirements.txt | 2 ++ vidura/settings.py | 4 +++- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/promptbook/admin.py b/promptbook/admin.py index da66711..dd81b27 100644 --- a/promptbook/admin.py +++ b/promptbook/admin.py @@ -1,6 +1,10 @@ from django.contrib import admin from .models import Category, Prompt, Label, PromptLabel +from reversion.admin import VersionAdmin # Register your models here. +@admin.register(Category) +class YourModelAdmin(VersionAdmin): + pass -admin.site.register([Category, Prompt, Label, PromptLabel]) \ No newline at end of file +admin.site.register([Prompt, Label, PromptLabel]) \ No newline at end of file diff --git a/promptbook/models.py b/promptbook/models.py index a12a23e..70fa461 100644 --- a/promptbook/models.py +++ b/promptbook/models.py @@ -4,6 +4,7 @@ from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import receiver +import reversion class Profile(models.Model): @@ -37,7 +38,7 @@ class Category(models.Model): def __str__(self): return self.name - +@reversion.register() class Prompt(models.Model): text = models.TextField() category = models.ForeignKey(Category, on_delete=models.DO_NOTHING) diff --git a/promptbook/views.py b/promptbook/views.py index 83f6f50..e8a3450 100644 --- a/promptbook/views.py +++ b/promptbook/views.py @@ -1,5 +1,5 @@ import json - +import reversion from enum import Enum from django.db import IntegrityError diff --git a/requirements.txt b/requirements.txt index 7b40ca2..87d1e12 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,5 @@ pillow==9.5.0 psycopg2-binary==2.9.6 django-allauth==0.54.0 djangorestframework==3.14.0 +python-dotenv==1.0.0 +django-reversion==5.0.4 \ No newline at end of file diff --git a/vidura/settings.py b/vidura/settings.py index 1a4fbf0..05ed8ff 100644 --- a/vidura/settings.py +++ b/vidura/settings.py @@ -12,9 +12,9 @@ from pathlib import Path import os +from dotenv import load_dotenv # load ENV and DJANGO_SETTINGS_MODULE from .env file -from dotenv import load_dotenv load_dotenv() # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -84,6 +84,7 @@ 'allauth.socialaccount', 'allauth.socialaccount.providers.google', 'rest_framework', + "reversion", ] MIDDLEWARE = [ @@ -94,6 +95,7 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'reversion.middleware.RevisionMiddleware', ] ROOT_URLCONF = 'vidura.urls'