def handle(self, *args, **options): username = options['username'] email = options['email'] first_name = options['first_name'] last_name = options['last_name'] password = options['password'] account_data = { 'username': username, 'password': password, 'email': email, 'first_name': first_name, 'last_name': last_name } account_data_qd = QueryDict('', mutable=True) account_data_qd.update(account_data) serializer = AccountSerializer(data=account_data_qd) if serializer.is_valid(): user = User.objects.create_superuser(**serializer.validated_data) UserRole.objects.create(name=ADMIN, user=user) self.stdout.write('Successfully created admin "%s"' % options['username']) return self.stdout.write('Invalid data!')
def set_password(self, request, pk=None): user = self.get_object() serializer = AccountSerializer(data=request.data) if serializer.is_valid(): user.set_password(serializer.data['password']) user.save() return Response({'status': 'password set'}) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)