-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMuebleEnLab.py
More file actions
55 lines (48 loc) · 1.78 KB
/
MuebleEnLab.py
File metadata and controls
55 lines (48 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import gettext_lazy as _
from LabModule.app_models.Laboratorio import Laboratorio
from LabModule.app_models.Mueble import Mueble
class MuebleEnLab(models.Model):
class Meta:
verbose_name = _("Mueble en Laboratorio")
verbose_name_plural = _('Muebles en Laboratorio')
app_label = 'LabModule'
unique_together = ('idLaboratorio', 'posX', 'posY')
idLaboratorio = models.ForeignKey(
Laboratorio,
blank = False,
null = True,
on_delete = models.CASCADE,
verbose_name = "Laboratorio",
related_name = '%(app_label)s_%(class)s_related'
)
idMueble = models.OneToOneField(
Mueble,
blank = False,
null = False,
on_delete = models.CASCADE,
verbose_name = "Mueble",
related_name = '%(app_label)s_%(class)s_related',
primary_key = True,
unique = True,
error_messages = {'unique': "Ya existe un mueble con este ID"}
)
posX = models.PositiveIntegerField(
verbose_name = "Fila",
null = False,
default = 0
)
posY = models.PositiveIntegerField(
verbose_name = "Columna",
null = False,
default = 0
)
def __unicode__(self):
return self.idLaboratorio.__unicode__() + ":" + str(self.posX) + "," + str(self.posY)
@classmethod
def es_ubicacion_libre(cls, id_lab, new_posX, new_posY):
return not MuebleEnLab.objects.filter(idLaboratorio = id_lab, posX = new_posX, posY = new_posY).exists()
@classmethod
def get_laboratorio(cls, mueble):
return MuebleEnLab.objects.get(idMueble = mueble).idLaboratorio