feat: 修改mroombooking表约束
This commit is contained in:
parent
2ca47b8949
commit
a3416cfc0d
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 3.2.12 on 2025-10-17 06:50
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ofm', '0021_alter_publicity_publicity_opinion'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name='mroomslot',
|
||||
unique_together=set(),
|
||||
),
|
||||
]
|
|
@ -45,9 +45,6 @@ class MroomSlot(BaseModel):
|
|||
slot = models.PositiveIntegerField('时段', help_text='0-47')
|
||||
is_inuse = models.BooleanField('是否占用', default=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('mroom', 'mdate', 'slot', 'is_inuse')
|
||||
|
||||
|
||||
# class Seal(BaseModel):
|
||||
# """TN: 印章类型"""
|
||||
|
|
|
@ -37,10 +37,10 @@ class MroomBookingSerializer(CustomModelSerializer):
|
|||
for slot in slots:
|
||||
if slot < 0 or slot > 47:
|
||||
raise ParseError("时段索引超出范围")
|
||||
try:
|
||||
MroomSlot.objects.create(booking=booking, slot=slot, mdate=mdate, mroom=mroom, is_inuse=True)
|
||||
except Exception as e:
|
||||
raise ParseError(f"时段已预订,请刷新重选-{e}")
|
||||
ms_exists = MroomSlot.objects.filter(mroom=mroom, mdate=mdate, slot=slot, is_inuse=True).exists()
|
||||
if ms_exists:
|
||||
raise ParseError("时段已预订,请刷新重选")
|
||||
MroomSlot.objects.create(booking=booking, slot=slot, mdate=mdate, mroom=mroom, is_inuse=True)
|
||||
return booking
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
|
@ -52,10 +52,10 @@ class MroomBookingSerializer(CustomModelSerializer):
|
|||
for slot in slots:
|
||||
if slot < 0 or slot > 47:
|
||||
raise ParseError("时段索引超出范围")
|
||||
try:
|
||||
MroomSlot.objects.create(booking=booking, slot=slot, mdate=mdate, mroom=mroom, is_inuse=True)
|
||||
except Exception as e:
|
||||
raise ParseError(f"时段已预订,请刷新重选-{e}")
|
||||
ms_exists = MroomSlot.objects.filter(mroom=mroom, mdate=mdate, slot=slot, is_inuse=True).exists()
|
||||
if ms_exists:
|
||||
raise ParseError("时段已预订,请刷新重选")
|
||||
MroomSlot.objects.create(booking=booking, slot=slot, mdate=mdate, mroom=mroom, is_inuse=True)
|
||||
return booking
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue