Skip to content

Commit 705bc2d

Browse files
author
Jon Heaton
committed
Merge branch 'jimmyho-master'
2 parents 6644c23 + 70811ec commit 705bc2d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

instagram/models.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def object_from_dictionary(cls, entry):
9999
for comment in entry['comments']['data']:
100100
new_media.comments.append(Comment.object_from_dictionary(comment))
101101

102+
new_media.users_in_photo = []
103+
if entry.get('users_in_photo'):
104+
for user_in_photo in entry['users_in_photo']:
105+
new_media.users_in_photo.append(UserInPhoto.object_from_dictionary(user_in_photo))
106+
102107
new_media.created_time = timestamp_to_datetime(entry['created_time'])
103108

104109
if entry['location'] and 'id' in entry:
@@ -208,3 +213,37 @@ def __unicode__(self):
208213
followed = False if self.incoming_status == 'none' else True
209214

210215
return "Relationship: (Follows: %s, Followed by: %s)" % (follows, followed)
216+
217+
218+
class Position(ApiModel):
219+
def __init__(self, x, y):
220+
self.x = x
221+
self.y = y
222+
223+
def __unicode__(self):
224+
return "Position: (%s, %s)" % (self.x, self.y)
225+
226+
@classmethod
227+
def object_from_dictionary(cls, entry):
228+
if 'x' in entry:
229+
return Position(entry['x'], entry['y'])
230+
231+
232+
class UserInPhoto(ApiModel):
233+
def __init__(self, user, position):
234+
self.position = position
235+
self.user = user
236+
237+
def __unicode__(self):
238+
return "UserInPhoto: (%s, %s)" % (self.user, self.position)
239+
240+
@classmethod
241+
def object_from_dictionary(cls, entry):
242+
user = None
243+
if 'user' in entry:
244+
user = User.object_from_dictionary(entry['user'])
245+
246+
if 'position' in entry:
247+
position = Position(entry['position']['x'], entry['position']['y'])
248+
249+
return UserInPhoto(user, position)

0 commit comments

Comments
 (0)