#23780: Easy to use natural keys from a tuple on meta
-------------------------------------+-------------------------------------
     Reporter:  scrummyin            |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Core                 |                  Version:  master
  (Serialization)                    |               Resolution:
     Severity:  Normal               |             Triage Stage:
     Keywords:                       |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by scrummyin:

Old description:

> Having to implement two methods on two different objects in order to use
> natural keys is very cumbersome. I would think we could implement
> something on a models meta to take a tuple of field names for use in both
> the natural_key and get_by_natural_key methods. I implemented this in a
> way that would be overridable to keep compatible with the current methods
> but would allow for easy use in the future. Working code with this is
> here
> https://github.com/scrummyin/django/commit/7e562127c3a9610ae3ad9fab6855a005f4d4706f.
> Includes 6 more tests around a two new methods, with same name but on the
> model and manager. Sll old tests are still working with minimal changes.
> The minimal change is to use a new method to check for a natural_key
> instead of hasattr.

New description:

 Having to implement two methods on two different objects in order to use
 natural keys is very cumbersome. I would think we could implement
 something on a models meta to take a tuple of field names for use in both
 the natural_key and get_by_natural_key methods. I implemented this in a
 way that would be overridable to keep compatible with the current methods
 but would allow for easy use in the future. Working code with this is here
 
https://github.com/scrummyin/django/commit/7e562127c3a9610ae3ad9fab6855a005f4d4706f.
 Includes 6 more tests around a two new methods, with same name but on the
 model and manager. The old tests are still working with minimal changes.
 The minimal change is to use a new method to check for a natural_key
 instead of hasattr. The pull request branch has all

--

--
Ticket URL: <https://code.djangoproject.com/ticket/23780#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.776a03e41caa066fdae0a6f42597e9b7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to