<commit_before>from rest_framework import serializers

from recipies.models import Recipe, RecipeMalts, RecipeHops

class RecipeSerializer(serializers.ModelSerializer):
  """Serialization class for all your yummy recipes."""

  recipe_malts = RecipeMaltsSerializer()
  recipe_hops = RecipeHopsSerialize()

  class Meta:
    model = Recipe
    fields = '__all__'

  def create(self, validated_data):
    """Create the recipe and all related data"""
    # As hops and malt will be handled separately, remove them from the current data.
    hops  = validated_data.pop("recipe_hops")
    malts = validated_data.get('recipe_malts')
    del validated_data['malts']
    user = validated_data.get('user')
    del validated_data['user']

    return Account.object.create_recipe(user, validated_data, malts, hops)

class RecipeMaltsSerializer(serializers.ModelSerializer):
  """Subserializer for Recipes. Handles the malts."""
  class Meta:
    model = RecipeMalts
    exclude = ('id',)

class RecipeHopsSerializer(serializers.ModelSerializer):
  """Subserializer for Recipes. Handles the hops."""
  class Meta:
    model  = RecipeHops
    exclude = ('id',)<commit_msg>Reordered the classes so that they worked correctly. Now my test JSON is invalid<commit_after>from rest_framework import serializers

from recipies.models import Recipe, RecipeMalts, RecipeHops

class RecipeMaltsSerializer(serializers.ModelSerializer):
  """Subserializer for Recipes. Handles the malts."""
  class Meta:
    model = RecipeMalts
    exclude = ('id',)

class RecipeHopsSerializer(serializers.ModelSerializer):
  """Subserializer for Recipes. Handles the hops."""
  class Meta:
    model  = RecipeHops
    exclude = ('id',)

class RecipeSerializer(serializers.ModelSerializer):
  """Serialization class for all your yummy recipes."""

  recipe_malts = RecipeMaltsSerializer()
  recipe_hops = RecipeHopsSerializer()

  class Meta:
    model = Recipe
    fields = '__all__'

  def create(self, validated_data):
    """Create the recipe and all related data"""
    # As hops and malt will be handled separately, remove them from the current data.
    hops  = validated_data.pop("recipe_hops")
    malts = validated_data.get('recipe_malts')
    del validated_data['malts']
    user = validated_data.get('user')
    del validated_data['user']

    return Account.object.create_recipe(user, validated_data, malts, hops)
{'fraction_non_alphanumeric': 0.09597652975691534, 'fraction_numerical': 0.0, 'mean_word_length': 4.590163934426229, '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': '2253764', 'n_tokens_mistral': 726, 'n_tokens_neox': 695, 'n_words': 204}