Remove old fields on dumpdata generated json

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#dumpfix.py

import json
import sys

def fix_dump(in_file, out_file, model, *remove_fields):
    content = json.load(open(in_file))
    
    for item in content:
        if item['model'] == model:
            for field in remove_fields:
                if field in item['fields']:
                    del item['fields'][field]
    
    json.dump(content, open(out_file, 'w'))
    
if __name__ == "__main__":
    """ 
    Usage: 
    python dumpfix.py olddump.json newdump.json myapp.mymodel field1 field2 ...
    """
    fix_dump(*sys.argv[1:])

More like this

  1. Export models as json by aconbere 6 years, 2 months ago
  2. Database migration and dump/load script by akaihola 6 years, 1 month ago
  3. Export Django data to datestamped tarball -- choose individual models for handy packaging and archiving by fish2000 2 years, 8 months ago
  4. Proper fixtures loading in south data migrations by JustDelight 2 months, 3 weeks ago
  5. dumpdata/loaddata with MySQL and ForeignKeys by cmgreen 5 years, 4 months ago

Comments

(Forgotten your password?)