{"action":"created","issue":{"url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/22","repository_url":"https://api.github.com/repos/beda-software/drf-writable-nested","labels_url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/22/comments","events_url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/22/events","html_url":"https://github.com/beda-software/drf-writable-nested/issues/22","id":265051808,"number":22,"title":"AssertionError: The `.create()` method does not support writable nested fields by default.","user":{"login":"beautifulDrifter","id":32745191,"avatar_url":"https://avatars0.githubusercontent.com/u/32745191?v=4","gravatar_id":"","url":"https://api.github.com/users/beautifulDrifter","html_url":"https://github.com/beautifulDrifter","followers_url":"https://api.github.com/users/beautifulDrifter/followers","following_url":"https://api.github.com/users/beautifulDrifter/following{/other_user}","gists_url":"https://api.github.com/users/beautifulDrifter/gists{/gist_id}","starred_url":"https://api.github.com/users/beautifulDrifter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beautifulDrifter/subscriptions","organizations_url":"https://api.github.com/users/beautifulDrifter/orgs","repos_url":"https://api.github.com/users/beautifulDrifter/repos","events_url":"https://api.github.com/users/beautifulDrifter/events{/privacy}","received_events_url":"https://api.github.com/users/beautifulDrifter/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-10-12T19:05:23Z","updated_at":"2017-10-13T16:58:19Z","closed_at":"2017-10-13T04:01:11Z","author_association":"NONE","body":"I am having trouble getting this to work.  I am still getting the following but I can very clearly see the .create in your code.\r\n\r\n> AssertionError: The `.create()` method does not support writable nested fields by default.\r\n\r\nI am hoping you can help me as this is exactly what I need.  I have tinkered this with for 2 days and have not been able to get around this AssertionError.  Below is the code to reproduce.  The data all looks correct, it just won't let me save it.\r\n\r\n\r\n\r\n\r\n```\r\nclass category(models.Model):\r\n    name = models.CharField(max_length=255, help_text=\"\",blank=True)\r\n    short_name = models.CharField(max_length=255, help_text=\"\",blank=True)\r\n    external_id = models.CharField(max_length=255, help_text=\"\",blank=True)\r\n   def __str__(self):\r\n        return self.name\r\n\r\nclass response_log(models.Model):\r\n    timestamp = models.DateTimeField()\r\n    status = models.CharField(max_length = 25)\r\n  \r\nclass response_log_detail(models.Model):\r\n    response_log = models.ForeignKey(response_log)\r\n    category = models.ManyToManyField(category)\r\n```\r\n\r\n\r\n```\r\nfrom rest_framework import serializers as s\r\nfrom drf_writable_nested import WritableNestedModelSerializer\r\n\r\nclass categoryArray(s.ModelSerializer):\r\n    # Fields #\r\n    categoryId = s.IntegerField(source='external_id')\r\n    categoryName = s.CharField(source='name')\r\n    categoryBriefName = s.CharField(source='short_name')\r\n\r\n    class Meta:\r\n        model = category\r\n        fields = (\r\n                'categoryId',\r\n                'categoryName',\r\n                'categoryBriefName',\r\n                )\r\n\r\nclass getCategoriesResponse(WritableNestedModelSerializer):\r\n    # Fields #\r\n    categoryArray = categoryArray(many=True)\r\n    # errorMessage = bonanzaErrorMessage()\r\n    # warnings = bonanzaWarnings()\r\n    class Meta:\r\n        model = response_log_detail\r\n        fields = (\r\n                'pk',\r\n                'categoryArray',\r\n                # 'errorMessage',\r\n                # 'warnings',\r\n                )\r\nclass responseSerializer(WritableNestedModelSerializer):\r\n    # Fields #\r\n    getCategoriesResponse = getCategoriesResponse()\r\n    ack = s.CharField(source='status')\r\n    class Meta:\r\n        model = response_log\r\n        fields = (\r\n        'pk',\r\n        'ack',\r\n        'getCategoriesResponse',\r\n        'timestamp',\r\n        )\r\n```\r\n\r\n```\r\nresponse = {'ack': 'Success',\r\n 'getCategoriesResponse': {'categoryArray': [{'categoryBriefName': 'Collectibles',\r\n    'categoryId': 1,\r\n    'categoryLevel': 1,\r\n    'categoryName': 'Collectibles',\r\n    'leafCategory': 'false',\r\n    'traitCount': 1},\r\n   {'categoryBriefName': 'Everything Else',\r\n    'categoryId': 99,\r\n    'categoryLevel': 1,\r\n    'categoryName': 'Everything Else',\r\n    'leafCategory': 'false',\r\n    'traitCount': 5}]},\r\n 'timestamp': '2017-10-12T12:00:40.000Z',\r\n 'version': '1.0'}\r\n\r\nserializer = responseSerializer(data = response)\r\nserializer.is_valid(raise_exception=True)\r\nresponse_log = serializer.save()\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/comments/336509206","html_url":"https://github.com/beda-software/drf-writable-nested/issues/22#issuecomment-336509206","issue_url":"https://api.github.com/repos/beda-software/drf-writable-nested/issues/22","id":336509206,"user":{"login":"beautifulDrifter","id":32745191,"avatar_url":"https://avatars0.githubusercontent.com/u/32745191?v=4","gravatar_id":"","url":"https://api.github.com/users/beautifulDrifter","html_url":"https://github.com/beautifulDrifter","followers_url":"https://api.github.com/users/beautifulDrifter/followers","following_url":"https://api.github.com/users/beautifulDrifter/following{/other_user}","gists_url":"https://api.github.com/users/beautifulDrifter/gists{/gist_id}","starred_url":"https://api.github.com/users/beautifulDrifter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beautifulDrifter/subscriptions","organizations_url":"https://api.github.com/users/beautifulDrifter/orgs","repos_url":"https://api.github.com/users/beautifulDrifter/repos","events_url":"https://api.github.com/users/beautifulDrifter/events{/privacy}","received_events_url":"https://api.github.com/users/beautifulDrifter/received_events","type":"User","site_admin":false},"created_at":"2017-10-13T16:58:19Z","updated_at":"2017-10-13T16:58:19Z","author_association":"NONE","body":"@ruscoder unfortunately I cannot reformat the json, so I am making my models fit to it for now.  I imagine that will be a typical use case as this will enable people to deserialize responses from external web services.  Now I am getting the error but on the second (inner) serializer.  \r\n\r\n> AssertionError: The `.create()` method does not support writable nested fields by default.\r\n> Write an explicit `.create()` method for serializer `modex_connect.serializers.getCategoriesResponse`, or set `read_only=True` on nested serializer fields.\r\n\r\nI have tried both setting a OneToOne on response_log_detail and a ForeignKey on response_log and neither have worked.  Eventually I will flatten these two models once I get the deserialization working.  I also removed the categoryArray from the getCategoriesResponse to validate that the responseSerializer worked properly and everything worked correctly.  The fix you added only seems to be taking effect on the top level serializer OR it has something to do with the many to many.  Let me know and thanks for all of your help!\r\n\r\nModels:\r\n\r\n```\r\nclass category(models.Model):\r\n    name = models.CharField(max_length=255, help_text=\"\", blank=True)\r\n    short_name = models.CharField(max_length=255, help_text=\"\", blank=True)\r\n    external_id = models.CharField(max_length=255, help_text=\"\", blank=True)\r\n    def __str__(self):\r\n        return self.name\r\n\r\nclass response_log_detail(models.Model):\r\n    category_id = models.ManyToManyField(category)\r\n    #response_log = models.OneToOneField(response_log, null = True, blank = True)\r\n     \r\nclass response_log(models.Model):\r\n    timestamp = models.DateTimeField()\r\n    status = models.CharField(max_length = 25, null=True, blank=True)\r\n    category_id = models.ManyToManyField(category)\r\n    response_log_detail = models.ForeignKey(response_log_detail, null=True, blank=True)\r\n```\r\n\r\n\r\nSerializers:\r\n\r\n```\r\nclass categoryArray(s.ModelSerializer):\r\n   \r\n    # Fields #\r\n    categoryId = s.IntegerField(source='external_id')\r\n    categoryName = s.CharField(source='name')\r\n    categoryBriefName = s.CharField(source='short_name')\r\n\r\n    class Meta:\r\n        model = category\r\n        fields = (\r\n                'categoryId',\r\n                'categoryName',\r\n                'categoryBriefName',\r\n                )\r\n\r\nclass getCategoriesResponse(WritableNestedModelSerializer):\r\n    # Fields #\r\n    categoryArray = categoryArray(many=True,source='category')\r\n    # errorMessage = bonanzaErrorMessage()\r\n    # warnings = bonanzaWarnings()\r\n    class Meta:\r\n        model = response_log_detail\r\n        fields = (\r\n                'pk',\r\n                'categoryArray',\r\n                # 'errorMessage',\r\n                # 'warnings',\r\n                )\r\n\r\nclass responseSerializer(WritableNestedModelSerializer):\r\n    # Fields #\r\n    getCategoriesResponse = getCategoriesResponse(source='response_log_detail')\r\n    ack = s.CharField(source='status')\r\n    timestamp = s.DateTimeField()\r\n    #getCategoriesResponse = getCategoriesResponse()\r\n    \r\n    \r\n    class Meta:\r\n        model = response_log\r\n        fields = (\r\n        'pk',\r\n        'getCategoriesResponse',\r\n        'ack',\r\n        'timestamp',\r\n        #'categoryArray',\r\n        )\r\n```\r\n\r\n"}}
{"actor":{"display_login":"beautifulDrifter"}}