50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
class Room(models.Model):
|
|
"""
|
|
Room definition.
|
|
|
|
"""
|
|
|
|
name = models.CharField(max_length=32, blank=False, unique=True, verbose_name=_("name"))
|
|
description = models.TextField(blank=True, verbose_name=_("description"))
|
|
width = models.PositiveIntegerField(default=0, help_text=_("centimeters"), verbose_name=_("width"))
|
|
length = models.PositiveIntegerField(default=0, help_text=_("centimeters"), verbose_name=_("length"))
|
|
height = models.PositiveIntegerField(default=0, help_text=_("centimeters"), verbose_name=_("height"))
|
|
|
|
class Meta:
|
|
verbose_name = _("room")
|
|
verbose_name_plural = _("rooms")
|
|
|
|
def get_area(self) -> int:
|
|
"""
|
|
Get the area of the room.
|
|
|
|
Returns:
|
|
Area of the room in square centimeters.
|
|
|
|
"""
|
|
return self.width * self.length
|
|
|
|
def get_volume(self) -> int:
|
|
"""
|
|
Get the volume of the room.
|
|
|
|
Returns:
|
|
Volume of the room in cube centimeters.
|
|
|
|
"""
|
|
return self.width * self.length * self.height
|
|
|
|
def is_empty(self) -> bool:
|
|
"""
|
|
Tell if the room is empty (has no volume).
|
|
|
|
Returns:
|
|
Whether the room has no volume (zero).
|
|
|
|
"""
|
|
return self.width * self.length * self.height == 0
|