from django.conf import settings
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _

ROLE_CHOICES = (
    ('User','User'),
    ('OtherRole','OtherRole'),
)

class UserProfile(models.Model):
    first_name = models.CharField(maxlength=30, core=True)
    last_name = models.CharField(maxlength=30, core=True)
    user = models.ForeignKey(User, unique=True, blank=True, null=True, edit_inline=models.TABULAR, 
                             num_in_admin=1,min_num_in_admin=1, max_num_in_admin=1,num_extra_on_change=0)
    dob = models.DateField(blank=True, null=True)   
    email = models.EmailField(blank=True)
    role = models.CharField(maxlength=30,choices=ROLE_CHOICES)
    notes = models.TextField("Notes",maxlength=500, blank=True)
    location = models.CharField(maxlength=50, blank=True, null=True)
    create_date = models.DateField(auto_now_add=True)
    def _get_full_name(self):
        "Returns the person's full name."
        return '%s %s' % (self.first_name, self.last_name)
    full_name = property(_get_full_name)
    otro_lang = models.CharField(_('Language'),maxlength=10,choices=settings.LANGUAGES,default=settings.LANGUAGE_CODE[:2], blank=True)
    # when viewing content in otro_lang your name will appear as otro_name
    otro_first_name = models.CharField(maxlength=30, blank=True)
    otro_last_name = models.CharField(maxlength=30, blank=True)
    def _get_otro_full_name(self):
        "Returns the person's otro language name."
        return '%s %s' % (self.otro_first_name, self.otro_last_name)
    otro_full_name = property(_get_otro_full_name)
    def __str__(self):
        return (self.full_name)

    class Admin:
        list_display = ('last_name','first_name','role')
        list_filter = ['create_date', 'role']
        ordering = ['last_name']

class Log(models.Model):
    what = models.CharField(maxlength=255)
    ldata = models.TextField(maxlength=1<<24 - 1)
    mtime = models.DateTimeField(auto_now = True)
    muser = models.CharField(maxlength=20)
    msg = models.TextField(maxlength=65535)
    class Meta:
	get_latest_by = 'id'

    class Admin:
        list_display = ('what','mtime','muser')
