Ryan Herriman  committed 71ea523

Added support for viewing attachments via the API.

  • Participants
  • Parent commits 384949b

Comments (0)

Files changed (2)

File leaves/

 	for f in obj._meta.fields:
 		if f.serialize and not in exclude:
 			d[] = _serialize(getattr(obj,
-	# Add the meta property if we're dealing with a Leaf.
+	# Add the attachment and meta properties if we're dealing with a Leaf.
 	if isinstance(obj, Leaf):
+		d['attachments'] = [model_to_dict(a, exclude=('leaf',)) for a in obj.attachment_list]
 		d['meta'] = obj.meta
 	return d

File leaves/

 			return self.get_absolute_url()
+	def get_attachments(self):
+		"""
+		Returns a list of all attachments for this leaf. Cached so subsequent
+		accesses do not hit the database.
+		"""
+		if not hasattr(self, '_attachment_cache'):
+			self._attachment_cache = [a for a in self.attachments.all()]
+		return self._attachment_cache
+	attachment_list = property(get_attachments)
 	def get_meta(self):
 		Returns a dictionary of all user-defined key/value pairs for this leaf.