How to use natural keys when dumping/loading fixture data for models that use generic relations?

53 views
Skip to first unread message

Stodge

unread,
Oct 2, 2014, 3:15:21 PM10/2/14
to django...@googlegroups.com
I'm trying to create fixtures for my Django application. We have our own app that provides per-object permissions. It uses a GenericForeignKey to assign permissions to many different models. I need the ability to define fixtures for these custom permissions. However, I'm having trouble understanding how to do this properly. All of my own models have natural keys defined. My object permission model has a uuid field, which is auto-generated in the overridden save function. It's also defined as the natural key for this model. When I dump existing object permissions, the JSON includes the object_id so it's not using the natural key. Here's an example:

{
    "pk": 7, 
    "model": "vault.vault", 
    "fields": {
        "groups": [], 
        "uuid": "11d62a7b-6e38-4baf-8938-fb475d8aca52", 
        "system": true, 
        "object_id": 3, 
        "content_type": [
            "myapp", 
            "mymodel"
        ], 
        "permissions": [], 
        "public": false, 
        "users": []
    }
}


I can't use this fixture as it's referencing an object ID. How do I use natural keys when dumping/loading fixture data for models that use generic relations? Thanks
Reply all
Reply to author
Forward
0 new messages