SHOW:
|
|
- or go back to the newest paste.
| 1 | from django.db import models | |
| 2 | from django.contrib.auth.models import User | |
| 3 | # Create your models here. | |
| 4 | ||
| 5 | class MatchManager(models.Manager): | |
| 6 | def user_matches(self, user): | |
| 7 | matches = [] | |
| 8 | if self.filter(from_user=user).count() > 0: | |
| 9 | obj = Match.objects.filter(from_user=user) | |
| 10 | for abc in obj: | |
| 11 | if abc.to_user != user: | |
| 12 | matches.append(abc.to_user) | |
| 13 | if self.filter(to_user=user).count() > 0: | |
| 14 | obj = Match.objects.filter(to_user=user) | |
| 15 | for abc in obj: | |
| 16 | if abc.from_user != user: | |
| 17 | matches.append(abc.from_user) | |
| 18 | return matches | |
| 19 | ||
| 20 | def are_matched(self, user1, user2): | |
| 21 | if self.filter(from_user=user1, to_user=user2).count() > 0: | |
| 22 | - | obj = Match.obejects.get(from_user=user1, to_user=user2) |
| 22 | + | obj = Match.objects.get(from_user=user1, to_user=user2) |
| 23 | perc = obj.percent * 100 | |
| 24 | if self.filter(from_user=user2, to_user=user1).count() > 0: | |
| 25 | - | obj = Match.obejects.get(from_user=user2, to_user=user1) |
| 25 | + | obj = Match.objects.get(from_user=user2, to_user=user1) |
| 26 | perc = obj.percent * 100 | |
| 27 | return perc | |
| 28 | else: | |
| 29 | return False | |
| 30 | ||
| 31 | class Match(models.Model): | |
| 32 | to_user = models.ForeignKey(User, related_name='match') | |
| 33 | from_user = models.ForeignKey(User, related_name='match2') | |
| 34 | percent = models.DecimalField(max_digits=10, decimal_places=4, default=75) | |
| 35 | ||
| 36 | objects = MatchManager() | |
| 37 | ||
| 38 | timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) | |
| 39 | updated = models.DateTimeField(auto_now_add=False, auto_now=True) | |
| 40 | ||
| 41 | def __unicode__(self): | |
| 42 | return self.percent |