Commits

Raoul Thill committed ff0ae89

Adding custom URLField handler, uses field name checks. If field name contains string 'image_url' an image will be displayed, otherwise a clickable links will be generated.

  • Participants
  • Parent commits 16fcfb5

Comments (0)

Files changed (1)

django_readonlywidget/widgets.py

         else:
             return ''
 
+    def get_urlfield_value(self, field_name, value):
+        """
+        Custom readonly urlfield handler
+        """
+        if value:
+            if 'image_url' in field_name:
+                return '<img width="180" height="180" src="%s">' % (value)
+            else:
+                return '<a target=_blank href="%s">%s</a>' % (value, value)
+        else:
+            return ''
+
     def get_imagefield_value(self, field_name, value):
         return self.get_filefield_value(field_name, value)