Skip to content

Commit

Permalink
models: change Message.get_mbox() into a property
Browse files Browse the repository at this point in the history
In order to use a CharField instead of a SerializerMethodField (which
is read-only and gets in the way when adding POST support), turn the
Message object's get_"mbox()" method into a property that can be simply
used like "msg.mbox".  In order to free the "mbox" name, all the existing
occurrences are changed to mbox_blob.

Message-Id: <20180508115051.60844-2-shubhamjain7495@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
shubhamdotjain authored and bonzini committed May 8, 2018
1 parent 254a321 commit beac6a9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions api/models.py
Expand Up @@ -321,19 +321,21 @@ class Message(models.Model):

objects = MessageManager()

def save_mbox(self, mbox):
save_blob(mbox, self.message_id)
def save_mbox(self, mbox_blob):
save_blob(mbox_blob, self.message_id)

def get_mbox_obj(self):
self.get_mbox()
return self._mbox_obj

def get_mbox(self):
if hasattr(self, "mbox"):
return self.mbox
self.mbox = load_blob(self.message_id)
self._mbox_obj = MboxMessage(self.mbox)
return self.mbox
if hasattr(self, "mbox_blob"):
return self.mbox_blob
self.mbox_blob = load_blob(self.message_id)
self._mbox_obj = MboxMessage(self.mbox_blob)
return self.mbox_blob

mbox = property(get_mbox)

def get_num(self):
assert self.is_patch or self.is_series_head
Expand Down

0 comments on commit beac6a9

Please sign in to comment.