This commit is contained in:
virusdefender 2018-05-17 01:13:54 +08:00
parent 675557668c
commit 796f748d10
3 changed files with 12 additions and 4 deletions

View File

@ -31,12 +31,17 @@ class DeleteGroupSerializer(serializers.Serializer):
class SimpleGroupSerializer(serializers.ModelSerializer):
created_by = UsernameSerializer()
password = serializers.SerializerMethodField()
me = serializers.BooleanField()
def get_password(self, obj):
return obj.password != ""
class Meta:
model = Group
fields = ["id", "created_by", "name"]
fields = ["id", "created_by", "name", "password", "me"]
class JoinGroupSerializer(serializers.Serializer):
group_name = serializers.CharField()
password = serializers.CharField()
password = serializers.CharField(allow_blank=True)

View File

@ -5,7 +5,10 @@ from ..serializers import SimpleGroupSerializer, JoinGroupSerializer
class GroupAPI(APIView):
def get(self, request):
return self.success(SimpleGroupSerializer(Group.objects.filter(allow_join=True).order_by("-id"), many=True).data)
groups = Group.objects.filter(allow_join=True).order_by("-id")
for item in groups:
item.me = item.members.filter(username=request.user.username).exists()
return self.success(SimpleGroupSerializer(groups, many=True).data)
@validate_serializer(JoinGroupSerializer)
def post(self, request):

View File

@ -180,7 +180,7 @@ REST_FRAMEWORK = {
)
}
REDIS_URL = "redis://:foobar@%s:%s" % (REDIS_CONF["host"], REDIS_CONF["port"])
REDIS_URL = "redis://@%s:%s" % (REDIS_CONF["host"], REDIS_CONF["port"])
def redis_config(db):