-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
406 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,7 @@ | |
'v1.news', | ||
'v1.list', | ||
'v1.menu', | ||
'v1.rating', | ||
|
||
'imagekit', | ||
'django_extensions', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
from django.contrib import admin | ||
from .models import Rating | ||
|
||
|
||
class RatingAdmin(admin.ModelAdmin): | ||
ordering = ['id', 'rating'] | ||
list_display = ['rating', 'comment', 'recipe', 'author'] | ||
list_filter = ['recipe', 'author'] | ||
search_fields = ['rating', 'comment', ] | ||
|
||
|
||
admin.site.register(Rating, RatingAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
from functools import reduce | ||
from .models import Rating | ||
|
||
|
||
def average_rating(recipe_id): | ||
ratings = Rating.objects.filter(recipe_id=recipe_id) | ||
if len(ratings) < 1: | ||
return 0 | ||
return reduce((lambda x, y: x + y), [r.rating for r in ratings]) / len(ratings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 2.0.1 on 2018-06-07 07:13 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('recipe', '0014_auto_20180607_0713'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Rating', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('comment', models.CharField(max_length=250, verbose_name='comment')), | ||
('rating', models.IntegerField(default=0, verbose_name='rating')), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
('recipe', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='recipe.Recipe')), | ||
], | ||
options={ | ||
'ordering': ['id'], | ||
}, | ||
), | ||
] |
28 changes: 28 additions & 0 deletions
28
v1/rating/migrations/0002_django_data_migration_recipe_to_rating.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 2.01 on 2018-06-07 | ||
from django.db import migrations | ||
|
||
|
||
def migrate_rating(apps, schema_editor): | ||
Recipe = apps.get_model('recipe', 'Recipe') | ||
Rating = apps.get_model('rating', 'Rating') | ||
for recipe in Recipe.objects.all(): | ||
rating = Rating.objects.create( | ||
recipe=recipe, | ||
author=recipe.author, | ||
rating=recipe.old_rating, | ||
comment='', | ||
) | ||
rating.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('rating', '0001_initial'), | ||
('recipe', '0014_auto_20180607_0713'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_rating), | ||
] |
Empty file.
Oops, something went wrong.