def add_to_class(cls, name, value):
django_meta_default_names = options.DEFAULT_NAMES
# patch django so Meta.get_pk_field can be specified these models
options.DEFAULT_NAMES = django_meta_default_names + ('get_pk_field',)
# We should call the contribute_to_class method only if it's bound
if not inspect.isclass(value) and hasattr(value, 'contribute_to_class'):
value.contribute_to_class(cls, name)
else:
try:
setattr(cls, name, value)
except AttributeError:
raise AttributeError('failed to set attribute {}'.format(name))
options.DEFAULT_NAMES = django_meta_default_names