Skip to content

Commit 2d99031

Browse files
committed
Add __qualname__ property to allow migration without problems
When django generate migration, it does a call do deconstruct, which recreate the models. ref: https://github.com/django/django/blob/master/django/db/migrations/operations/models.py#L74 When calling the __qualname__ attribute, a <local>.Mixin si returned and this can't be instanciated. Return the correct way to call in the __qualname__ attribute. Close bug #42.
1 parent f9e9afc commit 2d99031

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

django_prometheus/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from prometheus_client import Counter
2+
from functools import wraps
23

34
from django_prometheus.conf import NAMESPACE
45

@@ -37,7 +38,7 @@ class User(ExportModelOperationsMixin('user'), Model):
3738
model_updates.labels(model_name)
3839
model_deletes.labels(model_name)
3940

40-
class Mixin:
41+
class Mixin(object):
4142
def _do_insert(self, *args, **kwargs):
4243
model_inserts.labels(model_name).inc()
4344
return super()._do_insert(*args, **kwargs)
@@ -50,4 +51,5 @@ def delete(self, *args, **kwargs):
5051
model_deletes.labels(model_name).inc()
5152
return super().delete(*args, **kwargs)
5253

54+
Mixin.__qualname__ = "ExportModelOperationsMixin('{}')".format(model_name)
5355
return Mixin

0 commit comments

Comments
 (0)