1. Simon Meers
  2. django-model-utils

Commits

Carl Meyer  committed 605ef09

Fixed using SplitField on an abstract base model class.

  • Participants
  • Parent commits fe1ee72
  • Branches default

Comments (0)

Files changed (4)

File CHANGES.rst

View file
  • Ignore whitespace
 tip (unreleased)
 ----------------
 
+- Fixed using SplitField on an abstract base model.
+
 - Added pending-deprecation warnings for ``InheritanceCastModel``,
   ``manager_from``, and Django 1.1 support. Removed documentation for the
   deprecated utilities. Bumped ``ChoiceEnum`` from pending-deprecation to

File model_utils/fields.py

View file
  • Ignore whitespace
     A DateTimeField that updates itself on each save() of the model.
 
     By default, sets editable=False and default=datetime.now.
-    
+
     """
     def pre_save(self, model_instance, add):
         value = datetime.now()
     A DateTimeField that monitors another field on the same model and
     sets itself to the current date/time whenever the monitored field
     changes.
-    
+
     """
     def __init__(self, *args, **kwargs):
         kwargs.setdefault('default', datetime.now)
 
     def get_monitored_value(self, instance):
         return getattr(instance, self.monitor)
-    
+
     def _save_initial(self, sender, instance, **kwargs):
         setattr(instance, self.monitor_attname,
                 self.get_monitored_value(instance))
         if line.strip() == SPLIT_MARKER:
             return '\n'.join(excerpt)
         excerpt.append(line)
-            
+
     return '\n'.join(default_excerpt)
 
 class SplitText(object):
     def _get_has_more(self):
         return self.excerpt.strip() != self.content.strip()
     has_more = property(_get_has_more)
-    
+
     # allows display via templates without .content necessary
     def __unicode__(self):
         return self.content
         # rules below.
         self.add_excerpt_field = not kwargs.pop('no_excerpt_field', False)
         super(SplitField, self).__init__(*args, **kwargs)
-    
+
     def contribute_to_class(self, cls, name):
-        if self.add_excerpt_field:
+        if self.add_excerpt_field and not cls._meta.abstract:
             excerpt_field = models.TextField(editable=False)
             cls.add_to_class(_excerpt_field_name(name), excerpt_field)
         super(SplitField, self).contribute_to_class(cls, name)
         except AttributeError:
             return value
 
-        
+
 # allow South to handle these fields smoothly
 try:
     from south.modelsinspector import add_introspection_rules

File model_utils/tests/models.py

View file
  • Ignore whitespace
 
 
 
+class SplitFieldAbstractParent(models.Model):
+    content = SplitField()
+
+
+    class Meta:
+        abstract = True
+
+
+
 class NoRendered(models.Model):
     """
     Test that the no_excerpt_field keyword arg works. This arg should

File model_utils/tests/tests.py

View file
  • Ignore whitespace
     InheritanceManagerTestParent, InheritanceManagerTestChild1,
     InheritanceManagerTestChild2, TimeStamp, Post, Article, Status,
     StatusPlainTuple, TimeFrame, Monitored, StatusManagerAdded,
-    TimeFrameManagerAdded, Entry, Dude)
+    TimeFrameManagerAdded, Entry, Dude, SplitFieldAbstractParent)
 
 
 
         self.assertEquals(f.value_to_string(self.post), self.full_text)
 
 
+    def test_abstract_inheritance(self):
+        class Child(SplitFieldAbstractParent):
+            pass
+
+        self.assertEqual(
+            [f.name for f in Child._meta.fields],
+            ["id", "content", "_content_excerpt"])
+
+
+
 class MonitorFieldTests(TestCase):
     def setUp(self):
         self.instance = Monitored(name='Charlie')