~chipaca/unity-lens-video/custom-user-agent

« back to all changes in this revision

Viewing changes to main/models.py

  • Committer: Janos Gyerik
  • Date: 2012-02-05 07:44:37 UTC
  • Revision ID: janos@axiom-20120205074437-9atye2gcgkyof9pm
major refactoring: renamed WishListQuestion and WishListAnswer models to simply Question and Answer

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
        return self.vote_set.filter(up=False).count()
91
91
 
92
92
    def questions(self):
93
 
        return self.wishlistanswer_set.filter(question__is_published=True)
 
93
        return self.answer_set.filter(question__is_published=True)
94
94
 
95
95
    @staticmethod
96
96
    def get(pk):
123
123
        ordering = ('-id',)
124
124
 
125
125
 
126
 
class WishListQuestion(models.Model):
 
126
class Question(models.Model):
127
127
    user = models.ForeignKey(User)
128
128
    summary = models.CharField(max_length=200)
129
129
    explanation = models.TextField(blank=True, null=True)
135
135
        return '%s @%s' % (self.summary, self.user)
136
136
 
137
137
    def oneliners(self):
138
 
        return self.wishlistanswer_set.filter(oneliner__is_published=True)
 
138
        return self.answer_set.filter(oneliner__is_published=True)
139
139
 
140
140
    def accept_answer(self, oneliner):
141
141
        self.is_answered = True
152
152
    def save(self, *args, **kwargs):
153
153
        if not self.is_answered:
154
154
            AcceptedAnswer.objects.filter(question=self).delete()
155
 
        return super(WishListQuestion, self).save(*args, **kwargs)
 
155
        return super(Question, self).save(*args, **kwargs)
156
156
 
157
157
    @staticmethod
158
158
    def get(pk):
159
 
        return WishListQuestion.objects.get(pk=pk)
 
159
        return Question.objects.get(pk=pk)
160
160
 
161
161
    @staticmethod
162
162
    def top(limit=50):
163
 
        return WishListQuestion.objects.exclude(is_published=False).exclude(is_answered=True)[:limit]
 
163
        return Question.objects.exclude(is_published=False).exclude(is_answered=True)[:limit]
164
164
 
165
165
    @staticmethod
166
166
    def latest():
167
167
        try:
168
 
            return WishListQuestion.top(1)[0]
 
168
            return Question.top(1)[0]
169
169
        except:
170
170
            return None
171
171
 
174
174
        ordering = ('-id',)
175
175
 
176
176
 
177
 
class WishListAnswer(models.Model):
178
 
    question = models.ForeignKey(WishListQuestion)
 
177
class Answer(models.Model):
 
178
    question = models.ForeignKey(Question)
179
179
    oneliner = models.ForeignKey(OneLiner)
180
180
 
181
181
 
182
182
class AcceptedAnswer(models.Model):
183
 
    question = models.ForeignKey(WishListQuestion)
 
183
    question = models.ForeignKey(Question)
184
184
    oneliner = models.ForeignKey(OneLiner)
185
185
 
186
186
    class Meta: