[Django]-Django deserialize โ€“ I've specified a natural key manager but it wont' deserialize

5๐Ÿ‘

I found a solution that worked for me. It appears that the natural key expects a list instead of a single field, guessing they only planned natural key to be a combination of fieldsโ€™ values. I resolved this by return the zip_code in a list.

def natural_key(self):
    return [self.zip_code]

After doing this, the deserialization worked just as I wanted it to.

The resulted encoded JSON after doing this looked like this:

{
    "pk": 10661, 
    "model": "news.news", 
    "fields": {
        "content": "", 
        "created_on": "2012-07-25T10:19:56.627", 
        "location": [
            "36101"
        ], 
        "article_date": "2012-07-25T10:05:56", 
        "title": ""
    }
}
๐Ÿ‘คmikec

Leave a comment