Skip to content

Commit

Permalink
Remove description field and manage migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Sep 18, 2024
1 parent 08c275a commit 2767ce8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 64 deletions.
13 changes: 10 additions & 3 deletions content/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from django.contrib import admin

from content.models import Content
from common.admin import UserResourceAdmin
from content.models import Content, Tag

# Register your models here.


@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
list_display = ["name"]
search_fields = ["name"]


@admin.register(Content)
class ContentAdmin(admin.ModelAdmin):
class ContentAdmin(UserResourceAdmin):
list_display = ["title", "content_id"]
autocomplete_fields = ["created_by", "modified_by"]
autocomplete_fields = ["deleted_by", "tag"]
28 changes: 21 additions & 7 deletions content/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.1.1 on 2024-09-13 11:07
# Generated by Django 5.1.1 on 2024-09-18 05:10

import uuid

Expand Down Expand Up @@ -31,13 +31,25 @@ class Migration(migrations.Migration):
("created_at", models.DateTimeField(auto_now_add=True)),
("modified_at", models.DateTimeField(auto_now=True)),
("title", models.CharField(max_length=100)),
("document_type", models.IntegerField(choices=[(1, "Word"), (2, "PDF")])),
("document_type", models.IntegerField(choices=[(1, "Word"), (2, "PDF"), (3, "Text")], default=1)),
("document_file", models.FileField(upload_to="documents")),
("extracted_file", models.FileField(upload_to="documents")),
("extracted_file", models.FileField(blank=True, null=True, upload_to="documents-extracts")),
("content_id", models.UUIDField(default=uuid.uuid4, editable=False)),
("description", models.TextField()),
(
"document_status",
models.PositiveSmallIntegerField(
choices=[
(1, "Pending"),
(2, "Text extracted"),
(3, "Added to vector"),
(4, "Deleted from vector"),
(5, "Failure"),
],
default=1,
),
),
("is_deleted", models.BooleanField(default=False)),
("deleted_at", models.DateTimeField(null=True)),
("deleted_at", models.DateTimeField(blank=True, null=True)),
(
"created_by",
models.ForeignKey(
Expand All @@ -48,7 +60,9 @@ class Migration(migrations.Migration):
),
(
"deleted_by",
models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL
),
),
(
"modified_by",
Expand All @@ -58,7 +72,7 @@ class Migration(migrations.Migration):
to=settings.AUTH_USER_MODEL,
),
),
("tag", models.ManyToManyField(to="content.tag")),
("tag", models.ManyToManyField(blank=True, to="content.tag")),
],
options={
"ordering": ["-id"],
Expand Down

This file was deleted.

18 changes: 15 additions & 3 deletions content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ class Tag(models.Model):
name = models.CharField(max_length=20)
description = models.CharField(max_length=50, null=True, blank=True)

def __str__(self):
return self.name


class Content(UserResource):
class DocumentType(models.IntegerChoices):
WORD = 1, _("Word")
PDF = 2, _("PDF")
TEXT = 3, _("Text")

class DocumentStatus(models.IntegerChoices):
PENDING = 1, _("Pending")
Expand All @@ -24,13 +28,21 @@ class DocumentStatus(models.IntegerChoices):
FAILURE = 5, _("Failure")

title = models.CharField(max_length=100)
document_type = models.IntegerField(choices=DocumentType.choices, default=DocumentType.WORD)
document_file = models.FileField(upload_to="documents", blank=True)
document_type = models.IntegerField(choices=DocumentType.choices, default=DocumentType.TEXT)
document_file = models.FileField(upload_to="documents")
extracted_file = models.FileField(upload_to="documents-extracts", null=True, blank=True)
content_id = models.UUIDField(default=uuid.uuid4, editable=False)
description = models.TextField(help_text="Content text")
document_status = models.PositiveSmallIntegerField(choices=DocumentStatus.choices, default=DocumentStatus.PENDING)
tag = models.ManyToManyField("Tag", blank=True)
is_deleted = models.BooleanField(default=False)
deleted_at = models.DateTimeField(null=True, blank=True)
deleted_by = models.ForeignKey("user.User", null=True, blank=True, on_delete=models.PROTECT)

def __str__(self):
return self.title

def save(self, *args, **kwargs):
"""Save the content to the database."""
if self.document_type == self.DocumentType.TEXT:
self.extracted_file = self.document_file
super().save(*args, **kwargs)
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
DJANGO_DEBUG: ${DJANGO_DEBUG:-True}
DJANGO_ALLOWED_HOST: ${DJANGO_ALLOWED_HOST:-localhost}
DJNAGO_SECRET_KEY: ${DJANGO_SECRET_KEY}
DATABASE_NAME: ${DATABASE_NAME:-chatbot}
DATABASE_NAME: ${DATABASE_NAME:-postgres}
DATABASE_USER: ${DATABASE_USER:-postgres}
DATABASE_PASSWORD: ${DATABASE_PASSWORD:-postgres}
DATABASE_PORT: ${DATABASE_PORT:-5432}
Expand Down

0 comments on commit 2767ce8

Please sign in to comment.