diff --git a/otpauth/models.py b/otpauth/models.py index 564835e..0915443 100644 --- a/otpauth/models.py +++ b/otpauth/models.py @@ -13,16 +13,15 @@ class OTPSeed(AbstractUser): class Meta: unique_together = (('name', 'realm'),) + def save(self, *args, **kwargs): + """ + inject username to ensure it stays unique / is setup at all + """ + self.username = "{}@{}".format(self.name, self.realm) + super().save(*args, **kwargs) + def __str__(self): - return "'{}'@{}".format(self.name, self.realm) - - @property - def auth_name(self): - print("authname: {}".format(self)) - - @auth_name.setter - def auth_name(self): - print("authname: {}".format(self)) + return "'{}'@{} -- {}".format(self.name, self.realm, self.username) from otpauth.serializer import TokenSerializer diff --git a/otpauth/views.py b/otpauth/views.py index 2ab0e4d..ae3fd6e 100644 --- a/otpauth/views.py +++ b/otpauth/views.py @@ -30,7 +30,7 @@ from otpauth.models import OTPSeed class OTPVerifyViewSet(viewsets.ModelViewSet): - serializer_class = TokenSerializer + serializer_class = OTPSerializer queryset = OTPSeed.objects.all() def list(self, request):