# Path: users/models.py
# class UserProfile(models.Model):
# 
#     """
#     Model used to store more information on users
#     """
#     created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
#     updated_on = models.DateTimeField(_("Updated on"), auto_now=True)
#     user = models.OneToOneField(User, verbose_name=_("User"))
#     customer = models.ForeignKey(Customer, verbose_name=_(
#         "Customer"), on_delete=models.PROTECT, blank=True, null=True, default=None)
#     is_manager = models.BooleanField(
#         _("Is Manager"), help_text=_("Is this user a manager"), default=False)
#     manager = models.ForeignKey("self", verbose_name=_('Manager'), help_text=_(
#         "Select this user's manager"), blank=True, null=True, default=None, on_delete=models.PROTECT)
#     is_admin = models.BooleanField(
#         _("Is Administrator"), help_text=_("Should this user have administrative privileges"), default=False)
#     group = models.ManyToManyField(UserGroup, blank=True, default=None)
# 
#     class Meta:
#         verbose_name = _("User Profile")
#         verbose_name_plural = _("User Profiles")
#         ordering = ['user__first_name', 'created_on']
# 
#     def get_display_name(self):
#         if self.user.get_full_name():
#             return self.user.get_full_name()
#         return self.user.username
# 
#     def __str__(self):
#         return self.get_display_name()
# 
# class UserGroup(models.Model):
#     """
#     A group of users e.g. a department in an organisation
#     """
#     created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
#     updated_on = models.DateTimeField(_("Updated on"), auto_now=True)
#     customer = models.ForeignKey(Customer, verbose_name=_(
#         "Customer"), on_delete=models.PROTECT, blank=True, null=True, default=None)
#     name = models.CharField(_("Group Name"), max_length=300, blank=False)
#     parent = models.ForeignKey(
#         "self", verbose_name=_('Parent Group'), blank=True, null=True, default=None, on_delete=models.PROTECT)
#     manager = models.ForeignKey(
#         "UserProfile", verbose_name=_('Group Manager'), blank=True, null=True, default=None, on_delete=models.PROTECT)
# 
#     class Meta:
#         verbose_name = _("User Group")
#         verbose_name_plural = _("User Groups")
#         ordering = ['name']
# 
#     def __str__(self):
#         return self.name


from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from users.models import UserProfile, UserGroup


# Define an inline admin descriptor for UserProfile model
# which acts a bit like a singleton


class UserProfileInline(admin.StackedInline):
    model = UserProfile
    can_delete = False
    verbose_name_plural = 'UserProfile'

# Define a new User admin


class UserAdmin(UserAdmin):
    inlines = (UserProfileInline, )


class UserProfileAdmin(admin.ModelAdmin):
    list_display = ['user', 'customer']


class UserGroupAdmin(admin.ModelAdmin):
    list_display = ['name', 'customer', 'parent', 'manager']


# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

# Path: users/models.py
# class UserProfile(models.Model):
# 
#     """
#     Model used to store more information on users
#     """
#     created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
#     updated_on = models.DateTimeField(_("Updated on"), auto_now=True)
#     user = models.OneToOneField(User, verbose_name=_("User"))
#     customer = models.ForeignKey(Customer, verbose_name=_(
#         "Customer"), on_delete=models.PROTECT, blank=True, null=True, default=None)
#     is_manager = models.BooleanField(
#         _("Is Manager"), help_text=_("Is this user a manager"), default=False)
#     manager = models.ForeignKey("self", verbose_name=_('Manager'), help_text=_(
#         "Select this user's manager"), blank=True, null=True, default=None, on_delete=models.PROTECT)
#     is_admin = models.BooleanField(
#         _("Is Administrator"), help_text=_("Should this user have administrative privileges"), default=False)
#     group = models.ManyToManyField(UserGroup, blank=True, default=None)
# 
#     class Meta:
#         verbose_name = _("User Profile")
#         verbose_name_plural = _("User Profiles")
#         ordering = ['user__first_name', 'created_on']
# 
#     def get_display_name(self):
#         if self.user.get_full_name():
#             return self.user.get_full_name()
#         return self.user.username
# 
#     def __str__(self):
#         return self.get_display_name()
# 
# class UserGroup(models.Model):
#     """
#     A group of users e.g. a department in an organisation
#     """
#     created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
#     updated_on = models.DateTimeField(_("Updated on"), auto_now=True)
#     customer = models.ForeignKey(Customer, verbose_name=_(
#         "Customer"), on_delete=models.PROTECT, blank=True, null=True, default=None)
#     name = models.CharField(_("Group Name"), max_length=300, blank=False)
#     parent = models.ForeignKey(
#         "self", verbose_name=_('Parent Group'), blank=True, null=True, default=None, on_delete=models.PROTECT)
#     manager = models.ForeignKey(
#         "UserProfile", verbose_name=_('Group Manager'), blank=True, null=True, default=None, on_delete=models.PROTECT)
# 
#     class Meta:
#         verbose_name = _("User Group")
#         verbose_name_plural = _("User Groups")
#         ordering = ['name']
# 
#     def __str__(self):
#         return self.name


# Path: users/admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from users.models import UserProfile, UserGroup



# Define an inline admin descriptor for UserProfile model
# which acts a bit like a singleton


class UserProfileInline(admin.StackedInline):
    model = UserProfile
    can_delete = False
    verbose_name_plural = 'UserProfile'

# Define a new User admin


class UserAdmin(UserAdmin):
    inlines = (UserProfileInline, )


class UserProfileAdmin(admin.ModelAdmin):
    list_display = ['user', 'customer']


class UserGroupAdmin(admin.ModelAdmin):
    list_display = ['name', 'customer', 'parent', 'manager']


# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

admin.site.register(UserProfile, UserProfileAdmin)