from django.core.validators import RegexValidator
from django.db import models


class Department(models.Model):
    dept_name = models.CharField(max_length=100)
    home_unit = models.CharField(max_length=150)

    def __str__(self):
        return self.dept_name


class WidgetUser(models.Model):
    first_name = models.CharField(max_length=50)
    middle_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    # check if id_num string contains digits only
    id_num = models.CharField(max_length=7, validators=[RegexValidator(r'^\d+$')])
    email = models.EmailField(max_length=200)
    department = models.ForeignKey(Department, on_delete=models.CASCADE, null=True)
    image = models.ImageField(null = True, blank = True, upload_to = "homepage/")

    def __str__(self):
        full_name = self.first_name + " " + self.middle_name + " " + self.last_name
        return full_name
    
    def get_absolute_url(self):
        return u'%d/details' % self.pk