Skip to content

Instantly share code, notes, and snippets.

@csarcom
Last active October 31, 2015 04:37
Show Gist options
  • Save csarcom/9938033 to your computer and use it in GitHub Desktop.
Save csarcom/9938033 to your computer and use it in GitHub Desktop.
class Account(models.Model):
pass
class CustomUser(AbstractBaseUser, PermissionsMixin):
accounts = models.ManyToManyField(Account,
through='CustomUserAccount')
changed_by = models.ForeignKey(CustomUser, null=True, blank=True)
@property
def _history_user(self):
return self.changed_by
@_history_user.setter
def _history_user(self, value):
self.changed_by = value
....
class CustomUserAccount(models.Model):
user = models.ForeignKey(CustomUser)
account = models.ForeignKey('account.Account')
role = models.CharField(max_length=20)
changed_by = models.ForeignKey(CustomUser, null=True, blank=True,
related_name='changed_by_user')
@property
def _history_user(self):
return self.changed_by
@_history_user.setter
def _history_user(self, value):
self.changed_by = value
....
register(CustomUser)
register(CustomUserAccount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment