Commit 5c40ced6df8f3a71c8b4d06a2c7a9f33f62227b5
1 parent
89492339c3
Exists in
master
migrate default score value
Showing 2 changed files with 23 additions and 0 deletions Side-by-side Diff
flashcards/migrations/0019_auto_20150602_1046.py
View file @
5c40ced
1 | +# -*- coding: utf-8 -*- | |
2 | +from __future__ import unicode_literals | |
3 | + | |
4 | +from django.db import models, migrations | |
5 | + | |
6 | + | |
7 | +class Migration(migrations.Migration): | |
8 | + | |
9 | + dependencies = [ | |
10 | + ('flashcards', '0018_flashcard_score'), | |
11 | + ] | |
12 | + | |
13 | + operations = [ | |
14 | + migrations.AlterField( | |
15 | + model_name='flashcard', | |
16 | + name='score', | |
17 | + field=models.FloatField(default=0), | |
18 | + ), | |
19 | + ] |
flashcards/models.py
View file @
5c40ced
... | ... | @@ -29,6 +29,7 @@ |
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | + | |
32 | 33 | # Hack to fix AbstractUser before subclassing it |
33 | 34 | |
34 | 35 | AbstractUser._meta.get_field('email')._unique = True |
... | ... | @@ -324,6 +325,7 @@ |
324 | 325 | return self.is_hidden or self.flashcardhide_set.filter(user=user).exists() |
325 | 326 | |
326 | 327 | def is_in_deck(self, user): |
328 | + if hasattr(self, 'userflashcard_id'): return self.userflashcard_id | |
327 | 329 | return self.userflashcard_set.filter(user=user).exists() |
328 | 330 | |
329 | 331 | def edit(self, user, new_data): |
... | ... | @@ -404,6 +406,8 @@ |
404 | 406 | rqs = cls.objects.filter(Q(author__confirmed_email=True) | Q(author=user)) |
405 | 407 | # Exclude hidden cards |
406 | 408 | rqs = rqs.exclude(Q(is_hidden=True) | Q(flashcardhide__user=user)) |
409 | + # rqs = rqs.prefetch_related('userflashcard_set') | |
410 | + # rqs = rqs.aggregate(Count(userflashcard__user=user)) | |
407 | 411 | # Annotate the cards so we don't have to check if they're hidden in the future |
408 | 412 | return rqs.annotate(is_not_hidden=Value(True, output_field=BooleanField())) |
409 | 413 |