<commit_before>import os

from django.template.defaultfilters import filesizeformat
from django.utils import timezone
from django.contrib.auth.models import User, Group
from rest_framework import serializers
from rest_framework.reverse import reverse

from kive.serializers import AccessControlSerializer

from archive.models import Dataset, Run, MethodOutput
from librarian.models import SymbolicDataset
from metadata.serializers import CompoundDatatypeSerializer


class TinyRunSerializer(serializers.ModelSerializer):

    class Meta:
        model = Run
        fields = ('id',)


class DatasetSerializer(serializers.ModelSerializer):

    #user = serializers.StringRelatedField()
    user = serializers.SlugRelatedField(slug_field='username', read_only=True,
                                        default=serializers.CurrentUserDefault())

    compounddatatype = CompoundDatatypeSerializer(source='symbolicdataset.compounddatatype')
    filename = serializers.SerializerMethodField()
    filesize = serializers.IntegerField(source='get_filesize')
    filesize_display = serializers.SerializerMethodField()

    users_allowed = serializers.StringRelatedField(many=True, source="symbolicdataset.users_allowed")
    #users_allowed = serializers.SlugRelatedField(slug_field='username', queryset=User.objects.all(),
    #                                             many=True, allow_null=True, required=False)
    groups_allowed = serializers.StringRelatedField(many=True, source="symbolicdataset.groups_allowed")
    #groups_allowed = serializers.SlugRelatedField(slug_field='name', queryset=Group.objects.all(),
    #                                              many=True, allow_null=True, required=False)

    download_url = serializers.HyperlinkedIdentityField(view_name='dataset-download')
    removal_plan = serializers.HyperlinkedIdentityField(view_name='dataset-removal-plan')
    redaction_plan = serializers.HyperlinkedIdentityField(view_name='dataset-redaction-plan')
    symbolic_id = serializers.IntegerField(source='symbolicdataset.id')

    class Meta():
        model = Dataset
        fields = (<commit_msg>Trying to use SlugRelatedFields in DatasetSerializer.<commit_after>import os

from django.template.defaultfilters import filesizeformat
from django.utils import timezone
from django.contrib.auth.models import User, Group
from rest_framework import serializers
from rest_framework.reverse import reverse

from kive.serializers import AccessControlSerializer

from archive.models import Dataset, Run, MethodOutput
from librarian.models import SymbolicDataset
from metadata.serializers import CompoundDatatypeSerializer


class TinyRunSerializer(serializers.ModelSerializer):

    class Meta:
        model = Run
        fields = ('id',)


class DatasetSerializer(serializers.ModelSerializer):

    user = serializers.SlugRelatedField(
        source="symbolicdataset.user",
        slug_field='username',
        read_only=True,
        default=serializers.CurrentUserDefault())

    compounddatatype = CompoundDatatypeSerializer(source='symbolicdataset.compounddatatype')
    filename = serializers.SerializerMethodField()
    filesize = serializers.IntegerField(source='get_filesize')
    filesize_display = serializers.SerializerMethodField()

    users_allowed = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all(),
        many=True, allow_null=True, required=False
    )
    groups_allowed = serializers.SlugRelatedField(
        slug_field='name',
        queryset=Group.objects.all(),
        many=True, allow_null=True, required=False
    )

    download_url = serializers.HyperlinkedIdentityField(view_name='dataset-download')
    removal_plan = serializers.HyperlinkedIdentityField(view_name='dataset-removal-plan')
    redaction_plan = serializers.HyperlinkedIdentityField(view_name='dataset-redaction-plan')
    symbolic_id = serializers.IntegerField(source='symbolicdataset.id', read_only=False)

    class Meta():
        model = Dataset
        fields = (
{'fraction_non_alphanumeric': 0.08191041821331353, 'fraction_numerical': 0.0, 'mean_word_length': 4.462162162162162, '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': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1332306', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1038, 'n_words': 194}