jazzband / django-taggit

Simple tagging for django
https://django-taggit.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.34k stars 622 forks source link

Natural key support #708

Open lucemia opened 3 years ago

lucemia commented 3 years ago

Looks like taggit doesn't yet support loaddata / dumpdata with natural keys. https://docs.djangoproject.com/en/3.1/topics/serialization/#natural-keys

It will be great if django-taggit can add this feature.

rtpg commented 3 years ago

@lucemia here I guess you're suggesting that we just use a straightforward mapping of tag text to do a lookup? Seems pretty doable (with the usual caveats for custom tag types)

Trafire commented 3 months ago

Natural Keys Support

We have added natural keys support to the custom Tag model in the Django taggit library. This allows you to identify objects by human-readable identifiers rather than by their database ID.

python manage.py dumpdata taggit.Tag --natural-foreign --natural-primary > tags.json

python manage.py loaddata tags.json

By default tags use the name field as the natural key.

You can customize this in your own custom tag model by setting the natural_key_fields property on your model the required fields.