from django.db import models from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _ from model_utils.models import TimeStampedModel class Group(TimeStampedModel, models.Model): groupname = models.CharField(max_length=16, unique=True) gid = models.PositiveSmallIntegerField(unique=True, primary_key=True) descr = models.TextField(blank=True) passwd = models.CharField(max_length=128, blank=True) class User(TimeStampedModel, models.Model): username = models.CharField(max_length=64, unique=True) uid = models.PositiveSmallIntegerField(unique=True, primary_key=True) group = models.ForeignKey(Group) gecos = models.CharField(max_length=128, blank=True) homedir = models.CharField(max_length=256) shell = models.CharField(max_length=64) class Shadow(TimeStampedModel, models.Model): user = models.OneToOneField(User, primary_key=True) passwd = models.CharField(max_length=128) changedays = models.PositiveSmallIntegerField(blank=True, null=True) minage = models.PositiveSmallIntegerField(blank=True, null=True) maxage = models.PositiveSmallIntegerField(blank=True, null=True) gracedays = models.PositiveSmallIntegerField(blank=True, null=True) inactdays = models.PositiveSmallIntegerField(blank=True, null=True) expiredays = models.PositiveSmallIntegerField(blank=True, null=True, default=None) class AdditionalGroup(TimeStampedModel, models.Model): user = models.ForeignKey(User) group = models.ForeignKey(Group) class Meta: unique_together = ('user', 'group') def clean(self): if self.user.group == self.group: raise ValidationError(_( "You can not use a user's primary group."))