Add average and total playtime stats to user model
This commit is contained in:
@@ -24,6 +24,15 @@ class MinecraftProfile(models.Model):
|
||||
perms.append(perm.strip())
|
||||
return perms
|
||||
|
||||
def totalPlaytime(self):
|
||||
total = datetime.datetime.now()-datetime.datetime.now()
|
||||
for session in self.playersession_set.all():
|
||||
total = total + session.end-session.start
|
||||
return total
|
||||
|
||||
def averagePlaytime(self):
|
||||
return self.totalPlaytime()/len(self.playersession_set.all())
|
||||
|
||||
def __unicode__(self):
|
||||
return self.mc_username
|
||||
|
||||
|
@@ -13,6 +13,8 @@
|
||||
<li>Member Since: {{user.date_joined|date:"SHORT_DATE_FORMAT"}}</li>
|
||||
<li>Last seen: {{user.last_login|date:"SHORT_DATE_FORMAT"}}</li>
|
||||
<li>Invited here by: {{user.claimed_invite.creator|default:"Nobody!"}}</li>
|
||||
<li>Average Playtime: {{user.minecraftprofile.averagePlaytime}}</li>
|
||||
<li>Total Playtime: {{user.minecraftprofile.totalPlaytime}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
{%endblock%}
|
||||
|
Reference in New Issue
Block a user