Added convenience get_owner function
authorMikko Värri <vmj@linuxbox.fi>
Tue, 2 Feb 2010 00:40:23 +0000 (02:40 +0200)
committerMikko Värri <vmj@linuxbox.fi>
Tue, 2 Feb 2010 00:40:23 +0000 (02:40 +0200)
recycloid_models/models.py

index a438c33..d65abdb 100644 (file)
@@ -23,6 +23,9 @@ class IdentifiedModel(models.Model):
     def __unicode__(self):
         return u'%s %s' % (self.__class__.__name__, self.uuid)
 
+    def get_owner(self):
+        raise NotImplementedError()
+
 
 class StashServer(IdentifiedModel):
     """Stash server.
@@ -38,6 +41,13 @@ class StashServer(IdentifiedModel):
     def __unicode__(self):
         return u'%s' % self.url
 
+    def get_owner(self):
+        """Returns the StashOwner.
+
+        :return: An instance of recycloid_models.models.StashOwner
+        """
+        return StashOwner.objects.get(user__id=self.user_id)
+
 
 class StashOwner(IdentifiedModel):
     """Stash owner.
@@ -59,6 +69,13 @@ class StashOwner(IdentifiedModel):
     def __unicode__(self):
         return u'%s' % self.user.username
 
+    def get_owner(self):
+        """Returns the StashOwner.
+
+        :return: An instance of recycloid_models.models.StashOwner
+        """
+        return self
+
 
 class Stash(IdentifiedModel):
     """A stash of items.
@@ -90,6 +107,13 @@ class Stash(IdentifiedModel):
     def __unicode__(self):
         return u'%s' % self.title
 
+    def get_owner(self):
+        """Returns the StashOwner.
+
+        :return: An instance of recycloid_models.models.StashOwner
+        """
+        return self.owner
+
 
 class StashItem(IdentifiedModel):
     """An item in a stash.
@@ -116,6 +140,13 @@ class StashItem(IdentifiedModel):
     def __unicode__(self):
         return u'%s' % self.title
 
+    def get_owner(self):
+        """Returns the StashOwner.
+
+        :return: An instance of recycloid_models.models.StashOwner
+        """
+        return self.stash.get_owner()
+
 
 class StashItemImage(IdentifiedModel):
     """Detailed image of a stash item.
@@ -151,6 +182,13 @@ class StashItemImage(IdentifiedModel):
     def __unicode__(self):
         return u'%s' % self.url
 
+    def get_owner(self):
+        """Returns the StashOwner.
+
+        :return: An instance of recycloid_models.models.StashOwner
+        """
+        return self.item.get_owner()
+
 
 def on__user__post_save(sender, *args, **kwargs):
     """Callback for post_save signal from auth.models.User.