Commits

João Pedro Francese  committed c053997

Using django_inoa as an app now automatically replaces the base Django Model class's __unicode__() method.

  • Participants
  • Parent commits ef5236c

Comments (0)

Files changed (2)

File inoa/__init__.py

+# -*- coding: utf-8 -*-
+
+import django.db.models
+import inoa.models.utils
+
+setattr(django.db.models.Model, '__unicode__', inoa.models.utils.default_repr)

File inoa/models/utils.py

 from django.db.models.query import QuerySet
 
 def default_repr(obj, extra_info=None):
-    """Better default unicode representation for models."""
+    """
+    Better default unicode representation for models, which includes the instance verbose name and ID.
+    If the inoa app is in INSTALLED_APPS, this replaces all models' default __unicode__() method automatically.
+    """
     if extra_info:
         return u"#%d: %s" % (obj.id, extra_info)
     else:
         return u"%s #%d" % (obj._meta.verbose_name.capitalize(), obj.id)
-setattr(models.Model, '__unicode__', default_repr)
 
 def clone_instance(obj):
     """