The difference between get_by_natural_key and natural_key

As I understand it, the get_by_natural_key model manager is used for deserialization, and natural_key for serialization. It's true? If not, what are the differences?

And also, do we always need to specify the key --natural-foreign and --natural-primary? Is there a way to force serialization / deserialization through a natural key?

+6
source share
1 answer

As you say, Django uses get_by_natural_keyfor deserialization and natural_keyfor serialization.

As stated in the documentation, you do not need to define both of them. You can safely use only one of them.

, , serializers.serialize() use_natural_foreign_keys=True / use_natural_primary_keys=True.

/ admin.py dumpdata, --natural-foreign / --natural-primary, / () .

"" dumpdata, .

/ , , Django REST Framework serializer .

+3

All Articles