Skip to content

Commit

Permalink
Merge pull request #604 from ProtixIT/property-decorators
Browse files Browse the repository at this point in the history
Modernize property definitions in `SplitText`
  • Loading branch information
foarsitter authored Apr 3, 2024
2 parents d320924 + d1325d1 commit 53941ec
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions model_utils/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def __init__(self, instance, field_name, excerpt_field_name):
self.field_name = field_name
self.excerpt_field_name = excerpt_field_name

# content is read/write
@property
def content(self):
return self.instance.__dict__[self.field_name]
Expand All @@ -199,15 +198,13 @@ def content(self):
def content(self, val):
setattr(self.instance, self.field_name, val)

# excerpt is a read only property
def _get_excerpt(self):
@property
def excerpt(self):
return getattr(self.instance, self.excerpt_field_name)
excerpt = property(_get_excerpt)

# has_more is a boolean property
def _get_has_more(self):
@property
def has_more(self):
return self.excerpt.strip() != self.content.strip()
has_more = property(_get_has_more)

def __str__(self):
return self.content
Expand Down

0 comments on commit 53941ec

Please sign in to comment.