<commit_before>from rest_framework import serializers

from .models import Wallet, Transaction
from semillas_backend.users.serializers import UserSerializer


class CreateWalletSerializer(serializers.ModelSerializer):
    """ Usage:
    """

    class Meta:
        model = Wallet
        fields = ('uuid', 'owner', 'balance', 'last_updated', 'transactions')

class TransactionSerializer(CreateWalletSerializer):
    user = serializers.SerializerMethodField()
    balance = serializers.SerializerMethodField()
    class Meta:
        model = Transaction
        fields = ('id', 'value', 'balance', 'user', 'created_at')

    def get_user(self, obj):
        # if (self.request.wallet == obj)
        return 10

    def get_balance(self, obj):
        # if (self.request.user.wallet == obj)
        return 10


class WalletSerializer(CreateWalletSerializer):
    """ Usage:
        from rest_framework.renderers import JSONRenderer
        from semillas_backend.users.serializers import UserSerializer

        JSONRenderer().render(UserSerializer(user_instance).data)
    """
    transactions = TransactionSerializer(many=True)
    owner = UserSerializer()
<commit_msg>Adding more changes on Wallet & transation serializers<commit_after>from rest_framework import serializers

from .models import Wallet, Transaction
from semillas_backend.users.serializers import UserSerializer


class CreateWalletSerializer(serializers.ModelSerializer):
    """ Usage:
    """

    class Meta:
        model = Wallet
        fields = ('uuid', 'owner', 'balance', 'last_updated', 'transactions')

class TransactionSerializer(CreateWalletSerializer):
    user = serializers.SerializerMethodField()
    balance = serializers.SerializerMethodField()
    class Meta:
        model = Transaction
        fields = ('id', 'value', 'balance', 'user', 'created_at')

    def get_user(self, obj):
        # if (self.request.wallet == obj)
        return obj.wallet_dest.owner.name

    def get_balance(self, obj):
        # if (Wallet.objects.get(uuid=transactions.wallet) == obj.wallet_source):
        #     return obj.balance_source
        # else:
        #     return obj.balance_dest
        return obj.balance_source

class WalletSerializer(CreateWalletSerializer):
    """ Usage:
        from rest_framework.renderers import JSONRenderer
        from semillas_backend.users.serializers import UserSerializer

        JSONRenderer().render(UserSerializer(user_instance).data)
    """
    transactions = TransactionSerializer(many=True)
    owner = UserSerializer()

{'fraction_non_alphanumeric': 0.0989399293286219, 'fraction_numerical': 0.0015704750687082843, 'mean_word_length': 3.5663082437275984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5178827', 'n_tokens_mistral': 668, 'n_tokens_neox': 662, 'n_words': 159}