from django.contrib.auth.models import User, Group
from rest_framework import serializers


__all__ = ("UserSerializer", "GroupSerializer", "UserGroupSerializer")


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        exclude = ("password",)
        model = User


class GroupSerializer(serializers.ModelSerializer):
    class Meta:
        exclude = ("permissions",)
        model = Group


class UserGroupSerializer(serializers.ModelSerializer):
    group = GroupSerializer(read_only=True)
    user = UserSerializer(read_only=True)
    user_id = serializers.IntegerField()
    group_id = serializers.IntegerField()

    class Meta:
        model = User.groups.through
        fields = ("id", "group_id", "user_id", "group", "user")
