Skip to content

natural-keys 1.5.1

Compare
Choose a tag to compare
@sheppard sheppard released this 02 Sep 01:40

natural-keys 1.5.1 adds a defaults keyword argument to get_or_create_by_natural_key() and find(). This is based on the similar argument for get_or_create(), and is important when you have required fields on a model that are not part of a natural key.

While get_or_create() accepts keyword arguments, get_or_create_by_natural_key() and find() use positional arguments for the natural key fields (like get_by_natural_key()), with defaults being the only keyword argument.

instance, is_new = Event.objects.get_or_create_by_natural_key(
    'ABC123', date(2016, 1, 1),
    defaults={
        "name": "Example Event",
        "public": True,
    }
)