2018-07-27 13:13:42 +00:00
|
|
|
"""
|
2018-05-18 11:18:24 +00:00
|
|
|
This module contains pure wrapper functions used as decorators.
|
|
|
|
|
Functions in this module should be simple and not involve complex logic.
|
2018-07-27 13:13:42 +00:00
|
|
|
"""
|
2018-04-26 11:29:57 +00:00
|
|
|
|
2021-10-16 17:43:02 +00:00
|
|
|
|
2015-08-16 03:34:11 +00:00
|
|
|
def register_eav(**kwargs):
|
2018-07-27 13:13:42 +00:00
|
|
|
"""
|
2018-07-23 16:22:46 +00:00
|
|
|
Registers the given model(s) classes and wrapped ``Model`` class with
|
|
|
|
|
Django EAV 2::
|
2015-08-16 03:34:11 +00:00
|
|
|
|
2018-05-18 11:18:24 +00:00
|
|
|
@register_eav
|
|
|
|
|
class Author(models.Model):
|
|
|
|
|
pass
|
2018-07-27 13:13:42 +00:00
|
|
|
"""
|
2015-08-16 03:34:11 +00:00
|
|
|
from django.db.models import Model
|
|
|
|
|
|
2021-10-16 17:45:01 +00:00
|
|
|
from eav import register
|
2021-10-16 17:43:20 +00:00
|
|
|
|
2015-08-16 03:34:11 +00:00
|
|
|
def _model_eav_wrapper(model_class):
|
|
|
|
|
if not issubclass(model_class, Model):
|
|
|
|
|
raise ValueError('Wrapped class must subclass Model.')
|
|
|
|
|
register(model_class, **kwargs)
|
|
|
|
|
return model_class
|
|
|
|
|
|
2018-04-26 11:29:57 +00:00
|
|
|
return _model_eav_wrapper
|