'Encrypt Django auth User model's fields

I am trying to encrypt my username and email field in Djago's Default Auth model using a Proxy Model method but so far with no luck. Here is what I have attempted so far:

class UserManager(models.Manager):
def from_db_value(self, value, expression, connection):
    if value is None or value == '':
        return value
    # decrypt db value and return
    return decrypt(value)

def get_prep_value(self, value):
    # prepare value to be saved to the database.
    return encrypt(str(value))

class CustomUser(User):
  objects = UserManager()
  class Meta:
    proxy = True

  def print_value(self, value):
    print('test', value)

  def save(self, *args, **kwargs):
    self.user = self.print_value(self.user)
    super().save(*args, **kwargs)

I am trying to overwrite the User model with Proxy model and a custom Model manager. Any tips whether how can I achieve this would be really appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source