2023-11-18 11:57:50 +00:00
|
|
|
from django.core.files.base import ContentFile
|
|
|
|
from django.db import models, IntegrityError
|
2023-11-20 14:56:32 +00:00
|
|
|
from django_softdelete.models import SoftDeleteModel, SoftDeleteManager
|
2023-11-18 11:57:50 +00:00
|
|
|
|
|
|
|
|
2023-11-20 14:56:32 +00:00
|
|
|
class ItemManager(SoftDeleteManager):
|
2023-11-18 11:57:50 +00:00
|
|
|
|
|
|
|
def create(self, **kwargs):
|
|
|
|
if 'uid' in kwargs:
|
|
|
|
raise ValueError('uid must not be set manually')
|
2023-11-20 14:56:32 +00:00
|
|
|
#uid = Item.objects.filter(event=kwargs['event']).count() + 1
|
|
|
|
uid = Item.all_objects.filter(event=kwargs['event']).count() + 1
|
2023-11-18 11:57:50 +00:00
|
|
|
kwargs['uid'] = uid
|
|
|
|
return super().create(**kwargs)
|
|
|
|
|
|
|
|
|
2023-11-20 11:24:27 +00:00
|
|
|
class Item(SoftDeleteModel):
|
2023-11-18 11:57:50 +00:00
|
|
|
iid = models.AutoField(primary_key=True)
|
|
|
|
uid = models.IntegerField()
|
|
|
|
description = models.TextField()
|
|
|
|
event = models.ForeignKey('Event', models.CASCADE, db_column='eid')
|
|
|
|
container = models.ForeignKey('Container', models.CASCADE, db_column='cid')
|
|
|
|
returned_at = models.DateTimeField(blank=True, null=True)
|
|
|
|
created_at = models.DateTimeField(blank=True, null=True)
|
|
|
|
updated_at = models.DateTimeField(blank=True, null=True)
|
|
|
|
|
|
|
|
objects = ItemManager()
|
2023-11-20 14:56:32 +00:00
|
|
|
all_objects = models.Manager()
|
2023-11-18 11:57:50 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = (('uid', 'event'),)
|
2024-01-07 18:53:25 +00:00
|
|
|
permissions = [
|
|
|
|
('match_item', 'Can match item')
|
|
|
|
]
|
2023-11-18 11:57:50 +00:00
|
|
|
|
2023-11-20 11:24:27 +00:00
|
|
|
class Container(SoftDeleteModel):
|
2023-11-18 11:57:50 +00:00
|
|
|
cid = models.AutoField(primary_key=True)
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
created_at = models.DateTimeField(blank=True, null=True)
|
|
|
|
updated_at = models.DateTimeField(blank=True, null=True)
|
|
|
|
|
|
|
|
|
|
|
|
class Event(models.Model):
|
|
|
|
eid = models.AutoField(primary_key=True)
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
slug = models.CharField(max_length=255, unique=True)
|
|
|
|
start = models.DateTimeField(blank=True, null=True)
|
|
|
|
end = models.DateTimeField(blank=True, null=True)
|
|
|
|
pre_start = models.DateTimeField(blank=True, null=True)
|
|
|
|
post_end = models.DateTimeField(blank=True, null=True)
|
|
|
|
created_at = models.DateTimeField(blank=True, null=True)
|
|
|
|
updated_at = models.DateTimeField(blank=True, null=True)
|