from django.db import models
from utils.exceptions import CustomError
from apps.tenant.area.models import Area
from django.conf import settings

class Building(models.Model):
    building = models.CharField(verbose_name=u'楼宇', max_length=100)
    floor = models.CharField(verbose_name=u'楼层',max_length=100)
    location = models.CharField(verbose_name='地点', max_length=100)
    area = models.ForeignKey(Area, verbose_name=u'区域信息', on_delete=models.PROTECT, editable=False)
    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u"创建人", on_delete=models.PROTECT,
                                    editable=False)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

    class Meta:
        db_table = 'building'
        ordering = ['-id']
        verbose_name = u'建筑信息'
        default_permissions = ()
        permissions = [
            ('browse_building', u'查看'),
            ('add_building', u'添加'),
            ('delete_building', u'删除'),
        ]

    def get_full_name(self):
        return self.area.name+'-' +self.building + self.floor + self.location
