adiciona views, templates, urls e documentos do elastic search
This commit is contained in:
23
diarios/models.py
Normal file
23
diarios/models.py
Normal file
@ -0,0 +1,23 @@
|
||||
from django.db import models
|
||||
import PyPDF2
|
||||
|
||||
|
||||
class PDFDocument(models.Model):
|
||||
title = models.CharField(max_length=255)
|
||||
file = models.FileField(upload_to='pdfs/')
|
||||
content = models.TextField(blank=True)
|
||||
uploaded_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.file:
|
||||
pdf = PyPDF2.PdfReader(self.file)
|
||||
texto = []
|
||||
for pagina in pdf.pages:
|
||||
texto.append(pagina.extract_text())
|
||||
self.content = '\n'.join(texto)
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user