1 | | {{{ |
2 | | def build_instance(Model, data, db): |
3 | | obj = Model(**data) |
4 | | |
5 | | if obj.pk is None or (hasattr(Model, 'natural_key') and |
6 | | hasattr(Model._default_manager, 'get_by_natural_key')): |
7 | | natural_key = obj.natural_key() |
8 | | try: |
9 | | obj.pk = Model._default_manager.db_manager(db).get_by_natural_key(*natural_key).pk |
10 | | except Model.DoesNotExist: |
11 | | pass |
12 | | return obj |
13 | | }}} |
14 | | |
15 | | I can provide this solution: |
16 | | > if obj.pk is None or (hasattr(Model, 'natural_key') and hasattr(Model._default_manager, 'get_by_natural_key')): |
17 | | |
18 | | If `pk` isn't set, but `natural key` implementation exists - it goes to `updating pk` logic. |
19 | | |
20 | | I did test manually, it seems bug is fixed. |
21 | | Am I on right way, Daniel Knell? |
| 1 | UPD: False solution. |