Django 1.4: How to ignore fields, models in loaddata
Asked Answered
I

2

12

We have a compressed dumpdata of 15MB upload extracting goes to 100MB. It has few models & fields that are not used in current tables.

Specifically, there are few contenttypes models which can be ignored, and one field field_ that can be ignored in model.

Django 1.5 users -ignorenonexistent which safely does the job of ignoring. But how to do it efficiently in 1.4?

Issiah answered 22/5, 2014 at 3:17 Comment(0)
C
0

In Django 1.4, there isn't a built-in option like --ignorenonexistent available in the dumpdata command. However, you can still accomplish the same goal by creating a custom management command.

This custom command would allow you to specify which models and fields you want to exclude from the data dump. By filtering out these unwanted models and fields before running the dumpdata command, you can achieve a similar result to what --ignorenonexistent would do in newer versions of Django.

Chlorophyll answered 18/4 at 17:56 Comment(0)
W
0

Technically implementation of -ignorenonexistent is pretty simple, you may check this here from Django 1.5 source code.

So you need the same check somewhere here.

But how to achieve that?

According to Django 1.4.x (this page is loaded pretty slowly) this version of Django already had SERIALIZATION_MODULES setting. You can leverage it (why it can be useful you may check here).

# you need this for time of import-procedure only
# and only when you need behaviour of -ignorenonexistent option
# so use whatever you want: deleting\commenting\env.variable\whatever
SERIALIZATION_MODULES = { 'python': 'path.to.module.with.your.serializer.here' }

In you module path/to/module/with/your/serializer/here.py place the exact copy of this file (or just use inheritance to do less copy-pasting). And add the necessary check right into this file.

P.S.: You may hardcode you check or made it activated by environment variable too, whatever.

P.S.2: Shame on me but I realised only now that this a 9-year old question)) Stackoverflow, why you suggested me exact that question?))

Wendel answered 24/4 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.