Skip to content

Commit

Permalink
Make season field to a list
Browse files Browse the repository at this point in the history
  • Loading branch information
sepulzera committed Nov 21, 2024
1 parent 18fde39 commit 5c11edd
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 132 deletions.
64 changes: 38 additions & 26 deletions docs/ownrecipes-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,12 @@
"info": {
"type": "string"
},
"seasons": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Season"
}
},
"tags": {
"type": "array",
"items": {
Expand All @@ -1976,9 +1982,6 @@
"cuisine": {
"$ref": "#/components/schemas/Cuisine"
},
"season": {
"$ref": "#/components/schemas/Season"
},
"ingredient_groups": {
"type": "array",
"items": {
Expand Down Expand Up @@ -2026,10 +2029,10 @@
"required": [
"title",
"info",
"season",
"tags",
"course",
"cuisine",
"season",
"ingredient_groups",
"servings",
"directions",
Expand Down Expand Up @@ -2075,6 +2078,12 @@
"minimum": 0,
"description": "Zero means no rating."
},
"seasons": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Season"
}
},
"tags": {
"type": "array",
"items": {
Expand All @@ -2087,9 +2096,6 @@
"cuisine": {
"$ref": "#/components/schemas/Cuisine"
},
"season": {
"$ref": "#/components/schemas/Season"
},
"ingredient_groups": {
"type": "array",
"items": {
Expand Down Expand Up @@ -2163,6 +2169,7 @@
"title",
"info",
"rating",
"seasons",
"tags",
"ingredient_groups",
"servings",
Expand All @@ -2175,25 +2182,6 @@
"pub_date"
]
},
"Season": {
"title": "Season",
"type": "object",
"properties": {
"id": {
"type": "number",
"readOnly": true
},
"title": {
"type": "string",
"description": "Spring, Summer, Autumn, Winter",
"maxLength": 100
}
},
"required": [
"id",
"title"
]
},
"SubRecipe": {
"title": "SubRecipe",
"type": "object",
Expand Down Expand Up @@ -2229,6 +2217,30 @@
"denominator"
]
},
"Season": {
"title": "Season",
"type": "object",
"properties": {
"id": {
"type": "number",
"readOnly": true
},
"title": {
"type": "string",
"description": "spring, summer, autumn, winter",
"maxLength": 100
},
"slug": {
"type": "string",
"readOnly": true
}
},
"required": [
"id",
"title",
"slug"
]
},
"Tag": {
"title": "Tag",
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion v1/common/recipe_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_search_results(search_fields, queryset, search_term):
search_keyword_string (search_term)
)
query = get_search_results(
['title', 'ingredients__title', 'tags__title'],
['title', 'ingredients__title', 'seasons__title', 'tags__title'],
django_queryset,
'chicken taco'
)
Expand Down
4 changes: 2 additions & 2 deletions v1/common/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GetSearchResultsTests(TestCase):
def test_get_search_results(self):
""" Run a search that will return data """
query = get_search_results(
['title', 'ingredient_groups__ingredients__title', 'tags__title'],
['title', 'ingredient_groups__ingredients__title', 'seasons__title', 'tags__title'],
Recipe.objects,
'chili'
).distinct()
Expand All @@ -29,7 +29,7 @@ def test_get_search_results(self):
def test_get_search_no_results(self):
""" Run a search that will return no data """
query = get_search_results(
['title', 'ingredient_groups__ingredients__title', 'tags__title'],
['title', 'ingredient_groups__ingredients__title', 'seasons__title', 'tags__title'],
Recipe.objects,
'blue berry'
).distinct()
Expand Down
32 changes: 16 additions & 16 deletions v1/fixtures/recipe_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": 1,
"title": "Tasty Chili",
"course": 6,
"season": 1,
"seasons": [1],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -28,7 +28,7 @@
"author": 1,
"title": "Tasty Chili 2",
"course": 6,
"season": 1,
"seasons": [2, 3],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -47,7 +47,7 @@
"author": 1,
"title": "Tasty Chili 3",
"course": 6,
"season": 1,
"seasons": [1],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -66,7 +66,7 @@
"author": 1,
"title": "Tasty Chili 4",
"course": 6,
"season": 1,
"seasons": [1],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -85,7 +85,7 @@
"author": 1,
"title": "Tasty Chili 14",
"course": 6,
"season": 1,
"seasons": [1],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -104,7 +104,7 @@
"author": 1,
"title": "Tasty Chili 114",
"course": 6,
"season": 1,
"seasons": [1],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -122,7 +122,7 @@
"author": 1,
"title": "Tasty Chili 1114",
"course": 6,
"season": 1,
"seasons": [1],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -140,7 +140,7 @@
"author": 1,
"title": "Tasty Chili 2224",
"course": 6,
"season": 2,
"seasons": [2],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -158,7 +158,7 @@
"author": 1,
"title": "Tasty Chili 24",
"course": 6,
"season": 2,
"seasons": [2],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -176,7 +176,7 @@
"author": 1,
"title": "Tasty Chili 224",
"course": 6,
"season": 2,
"seasons": [2],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -194,7 +194,7 @@
"author": 1,
"title": "Tasty Chili 334",
"course": 6,
"season": 3,
"seasons": [3],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -212,7 +212,7 @@
"author": 1,
"title": "Tasty Chili 3334",
"course": 6,
"season": 3,
"seasons": [3],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -230,7 +230,7 @@
"author": 1,
"title": "Tasty Chili 33334",
"course": 6,
"season": 3,
"seasons": [3],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -248,7 +248,7 @@
"author": 1,
"title": "Tasty Chili 444",
"course": 6,
"season": 4,
"seasons": [4],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -266,7 +266,7 @@
"author": 1,
"title": "Tasty Chili 44",
"course": 6,
"season": 4,
"seasons": [4],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand All @@ -284,7 +284,7 @@
"author": 1,
"title": "Tasty Chili 444",
"course": 6,
"season": 4,
"seasons": [4],
"servings": 8,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
Expand Down
12 changes: 4 additions & 8 deletions v1/fixtures/season_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,32 @@
"pk": 1,
"model": "recipe_groups.season",
"fields": {
"author": 1,
"slug": "spring",
"title": "Spring"
"title": "spring"
}
},
{
"pk": 2,
"model": "recipe_groups.season",
"fields": {
"author": 1,
"slug": "summer",
"title": "Summer"
"title": "summer"
}
},
{
"pk": 3,
"model": "recipe_groups.season",
"fields": {
"author": 1,
"slug": "autumn",
"title": "Autumn"
"title": "autumn"
}
},
{
"pk": 4,
"model": "recipe_groups.season",
"fields": {
"author": 1,
"slug": "winter",
"title": "Winter"
"title": "winter"
}
}
]
4 changes: 2 additions & 2 deletions v1/rating/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get(self, request):

if 'season' in self.request.query_params:
try:
filter_set['season__in'] = Season.objects.filter(
filter_set['seasons__in'] = Season.objects.filter(
slug__in=self.request.query_params.get('season').split(',')
)
except:
Expand All @@ -71,7 +71,7 @@ def get(self, request):

if 'search' in self.request.query_params:
query = get_search_results(
['title', 'ingredient_groups__ingredients__title', 'tags__title'],
['title', 'ingredient_groups__ingredients__title', 'seasons__title', 'tags__title'],
query,
self.request.query_params.get('search')
).distinct()
Expand Down
2 changes: 1 addition & 1 deletion v1/recipe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class RecipeAdmin(admin.ModelAdmin):
list_display = ['title', 'author', 'pub_date']
list_filter = ['author', 'course', 'cuisine', 'season']
list_filter = ['author', 'course', 'cuisine']
search_fields = ['author__username', 'title',]
readonly_fields = ['rating', 'rating_count']

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 4.2.16 on 2024-11-14 08:46
# Generated by Django 4.2.16 on 2024-11-21 13:08

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +13,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AddField(
model_name='recipe',
name='season',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='recipe_groups.season'),
name='seasons',
field=models.ManyToManyField(blank=True, to='recipe_groups.season', verbose_name='season'),
),
]
4 changes: 2 additions & 2 deletions v1/recipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Recipe(models.Model):
Courses have a one to Many relation with Recipes.
Cuisines have a one to Many relation with Recipes.
Seasons have a one to Many relation with Recipes.
Seasons have a Many to Many relation with Recipes.
Tags have a Many to Many relation with Recipes.
Ingredient Groups have a Many to one relation with Recipes.
Subrecipes have a Many to Many relation with Recipes.
Expand Down Expand Up @@ -77,7 +77,7 @@ class Recipe(models.Model):
options={'quality': 70})
cuisine = models.ForeignKey(Cuisine, on_delete=models.CASCADE, null=True, blank=True)
course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True, blank=True)
season = models.ForeignKey(Season, on_delete=models.CASCADE, null=True, blank=True)
seasons = models.ManyToManyField(Season, verbose_name=_('season'), blank=True)
tags = models.ManyToManyField(Tag, verbose_name=_('tag'), blank=True)
subrecipes = models.ManyToManyField('self', verbose_name=_('subrecipes'), through='SubRecipe', symmetrical=False)
info = models.TextField(_('info'), help_text="enter information about the recipe", blank=True)
Expand Down
Loading

0 comments on commit 5c11edd

Please sign in to comment.