fix document deletion
This commit is contained in:
parent
d10d7cfe5f
commit
504b7b3cac
1 changed files with 8 additions and 3 deletions
|
@ -3,7 +3,8 @@ import markdown2
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.files.storage import FileSystemStorage
|
from django.core.files.storage import FileSystemStorage
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Count, Q, QuerySet
|
from django.db.models import Count, Q
|
||||||
|
from model_utils.managers import SoftDeletableManager, SoftDeletableQuerySet
|
||||||
from model_utils.models import SoftDeletableModel
|
from model_utils.models import SoftDeletableModel
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ class Tag(SoftDeletableModel):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class DocumentQuerySet(QuerySet):
|
class DocumentQuerySet(SoftDeletableQuerySet):
|
||||||
def untagged(self):
|
def untagged(self):
|
||||||
return super().annotate(tag_count=Count('tags')).filter(tag_count=0)
|
return super().annotate(tag_count=Count('tags')).filter(tag_count=0)
|
||||||
|
|
||||||
|
@ -26,6 +27,10 @@ class DocumentQuerySet(QuerySet):
|
||||||
return super().filter((Q(file__isnull=True) | Q(file='')) & ~Q(external_url__contains="pile.sdbs.cz"))
|
return super().filter((Q(file__isnull=True) | Q(file='')) & ~Q(external_url__contains="pile.sdbs.cz"))
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentManager(SoftDeletableManager):
|
||||||
|
_queryset_class = DocumentQuerySet
|
||||||
|
|
||||||
|
|
||||||
class Document(SoftDeletableModel):
|
class Document(SoftDeletableModel):
|
||||||
class DocumentStatus(models.TextChoices):
|
class DocumentStatus(models.TextChoices):
|
||||||
REFERENCE = "REF", "Referential"
|
REFERENCE = "REF", "Referential"
|
||||||
|
@ -44,7 +49,7 @@ class Document(SoftDeletableModel):
|
||||||
tags = models.ManyToManyField(Tag, related_name="documents", blank=True)
|
tags = models.ManyToManyField(Tag, related_name="documents", blank=True)
|
||||||
uploaded = models.DateTimeField(auto_now_add=True, null=True)
|
uploaded = models.DateTimeField(auto_now_add=True, null=True)
|
||||||
|
|
||||||
objects = DocumentQuerySet.as_manager()
|
objects = DocumentManager()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def html_description(self):
|
def html_description(self):
|
||||||
|
|
Loading…
Reference in a new issue