From 7e1e6769094edfd7aea5c138da3794fa0f9276d7 Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Sat, 7 Dec 2024 22:00:29 +0000 Subject: [PATCH] implement imagememo model in db --- penparse/webui/migrations/0002_imagememo.py | 30 +++++++ penparse/webui/models.py | 18 +++++ penparse/webui/templates/main.html | 4 +- penparse/webui/templates/partial/nav.html | 2 +- pyproject.toml | 1 + uv.lock | 88 ++++++++++++++++++++- 6 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 penparse/webui/migrations/0002_imagememo.py diff --git a/penparse/webui/migrations/0002_imagememo.py b/penparse/webui/migrations/0002_imagememo.py new file mode 100644 index 0000000..9944d42 --- /dev/null +++ b/penparse/webui/migrations/0002_imagememo.py @@ -0,0 +1,30 @@ +# Generated by Django 4.2.16 on 2024-12-07 21:54 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('webui', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='ImageMemo', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('image', models.ImageField(upload_to='')), + ('content', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='memos', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'ordering': ['-created_at'], + }, + ), + ] diff --git a/penparse/webui/models.py b/penparse/webui/models.py index de2610d..6d0fb4a 100644 --- a/penparse/webui/models.py +++ b/penparse/webui/models.py @@ -2,6 +2,8 @@ from django.contrib.auth.models import AbstractUser from django.contrib.auth.base_user import BaseUserManager from django.db import models +from uuid import uuid4 + class UserManager(BaseUserManager): """Define a model manager for User model with no username field.""" @@ -37,6 +39,22 @@ class UserManager(BaseUserManager): return self._create_user(email, password, **extra_fields) +class ImageMemo(models.Model): + """Model definition for ImageMemo.""" + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) + image = models.ImageField() + content = models.TextField() + + author = models.ForeignKey( + 'User', on_delete=models.CASCADE, related_name='memos') + + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + class Meta: + ordering = ["-created_at"] + + class User(AbstractUser): email = models.EmailField(unique=True) username = None diff --git a/penparse/webui/templates/main.html b/penparse/webui/templates/main.html index 4a127bf..918f1e7 100644 --- a/penparse/webui/templates/main.html +++ b/penparse/webui/templates/main.html @@ -3,7 +3,7 @@ - AnnoMemo - Intelligent OCR for Handwritten Notes + PenParse - Intelligent OCR for Handwritten Notes @@ -15,7 +15,7 @@ diff --git a/penparse/webui/templates/partial/nav.html b/penparse/webui/templates/partial/nav.html index 582e71f..14facba 100644 --- a/penparse/webui/templates/partial/nav.html +++ b/penparse/webui/templates/partial/nav.html @@ -1,5 +1,5 @@