django-orchestra/orchestra/apps/accounts/models.py

36 lines
1.2 KiB
Python
Raw Normal View History

2014-07-29 20:10:37 +00:00
from django.conf import settings as djsettings
2014-05-08 16:59:35 +00:00
from django.db import models
2014-07-29 20:10:37 +00:00
from django.utils.functional import cached_property
2014-05-08 16:59:35 +00:00
from django.utils.translation import ugettext_lazy as _
2014-07-10 10:03:22 +00:00
from orchestra.core import services
2014-05-08 16:59:35 +00:00
from . import settings
class Account(models.Model):
2014-07-29 20:10:37 +00:00
user = models.OneToOneField(djsettings.AUTH_USER_MODEL,
verbose_name=_("user"), related_name='accounts')
type = models.CharField(_("type"), choices=settings.ACCOUNTS_TYPES,
max_length=32, default=settings.ACCOUNTS_DEFAULT_TYPE)
2014-05-08 16:59:35 +00:00
language = models.CharField(_("language"), max_length=2,
choices=settings.ACCOUNTS_LANGUAGES,
default=settings.ACCOUNTS_DEFAULT_LANGUAGE)
register_date = models.DateTimeField(_("register date"), auto_now_add=True)
comments = models.TextField(_("comments"), max_length=256, blank=True)
is_active = models.BooleanField(default=True)
def __unicode__(self):
return self.name
2014-07-29 20:10:37 +00:00
@cached_property
2014-05-08 16:59:35 +00:00
def name(self):
2014-07-29 20:10:37 +00:00
return self.user.username
2014-08-19 18:59:23 +00:00
@classmethod
def get_main(cls):
return cls.objects.get(pk=settings.ACCOUNTS_MAIN_PK)
2014-07-10 10:03:22 +00:00
services.register(Account, menu=False)