Limit the output of a field

1
2
3
4
5
def limitfield (self,obj):
     if  len(obj.field) < 30:
       return obj.field
     else:
       return obj.field[:26]+'...'

More like this

  1. Unlimited-length CharField by rfugger 1 year ago
  2. Limit queryset to objects related to parent in ManyToMany fields within admin inlines by DrMeers 1 year, 8 months ago
  3. JSON View Decorator by bryanpieper 1 year, 7 months ago
  4. CountryField (UN Country List, 3 Char Codes) by djm 3 years ago
  5. Dynamically add css-classes to formfields by Lacour 7 months ago

Comments

(Forgotten your password?)