Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use as a decorator #12

Open
scnerd opened this issue Jan 14, 2020 · 3 comments
Open

Use as a decorator #12

scnerd opened this issue Jan 14, 2020 · 3 comments

Comments

@scnerd
Copy link

scnerd commented Jan 14, 2020

Requiring that a model inherit from NaturalKeyModel can conflict with other model modifiers that also requiring inheritance. It would be nice if the same functionality could be exposed via a class decorator. E.g.,

@NaturallyKeyedModel
class MyModel(SomeOtherModelSuperclass):
    # ...
@sheppard
Copy link
Member

I could see some benefit for a decorator, but the underlying mechanism will still probably require model inheritance. Would this problem be solved by providing a NaturalKeyMixin class instead?

class NaturalKeyMixin:
    objects = NaturalKeyModelManager()
    @classmethod
    def get_natural_key_info(cls):
         # ...
    # ...

class NaturalKeyModel(NaturalKeyMixin, models.Model):
    class Meta:
        abstract = True

Can you provide some specific examples of other model modifiers that conflict with natural keys?

@scnerd
Copy link
Author

scnerd commented Aug 24, 2021

I suspect a mixin would do the trick just fine, and would be more natural than my proposed class decorator.

It's clearly been a while since I first had this need, but I think I'd had my own custom Model class that added some functionality I wanted, probably overriding the default objects manager or something. I figured out a different approach for that so I could use this library, but requiring that my models inherit from NaturalKeyModel rather than be able to construct my own superclass (or superclasses provide by other libraries) definitely limited the possibilities for mixing this library with other needs.

@mattbuff
Copy link

Adding a NaturalKeyMixin to this package would provide compatibility with models that inherit from GeoDjango models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants