添加提交
This commit is contained in:
@@ -63,7 +63,7 @@ def list(request, username: str, role: str = None):
|
||||
users = User.objects.filter(username__icontains=username)
|
||||
if role:
|
||||
users = users.filter(role=role)
|
||||
return [UserListSchema.from_orm(user) for user in users]
|
||||
return [UserListSchema.get(user) for user in users]
|
||||
|
||||
|
||||
@router.post("/batch")
|
||||
|
||||
@@ -51,6 +51,10 @@ class Profile(models.Model):
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
|
||||
def update_total_score(self, score: int):
|
||||
self.total_score = self.total_score + score
|
||||
self.save()
|
||||
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
def create_user_profile(sender, instance, created, **kwargs):
|
||||
|
||||
@@ -6,8 +6,8 @@ from .models import User, RoleChoices
|
||||
|
||||
|
||||
class UserListSchema(ModelSchema):
|
||||
@classmethod
|
||||
def from_orm(cls, obj):
|
||||
@staticmethod
|
||||
def get(cls, obj):
|
||||
raw_password = obj.raw_password if obj.role == RoleChoices.NORMAL else ""
|
||||
return cls(
|
||||
id=obj.id,
|
||||
|
||||
Reference in New Issue
Block a user