diff --git a/pure_plate/db.sqlite3 b/pure_plate/db.sqlite3 index eac96d7..87b990b 100644 Binary files a/pure_plate/db.sqlite3 and b/pure_plate/db.sqlite3 differ diff --git a/pure_plate/restaurant/models.py b/pure_plate/restaurant/models.py index a233746..db5c2f4 100644 --- a/pure_plate/restaurant/models.py +++ b/pure_plate/restaurant/models.py @@ -1,13 +1,6 @@ from django.db import models from django.db.models import Avg -# class Category(models.Model): -# category_id = models.AutoField(primary_key=True) -# category_name = models.CharField(max_length=50, db_index=True) - -# class Meta: -# verbose_name_plural = "categories" - class Restaurant(models.Model): name = models.CharField(max_length=255, db_index=True) address = models.CharField(max_length=255) @@ -18,7 +11,6 @@ class Restaurant(models.Model): phone = models.CharField(max_length=255, db_index=True) review_count = models.IntegerField(default=0) avg_rating = models.DecimalField(max_digits=3, decimal_places=2, default=0.00) - # categories = models.ManyToManyField(Category, related_name='restaurants') vegan=models.BooleanField(default=False) halal=models.BooleanField(default=False) gluten_free=models.BooleanField(default=False) diff --git a/pure_plate/restaurant/urls.py b/pure_plate/restaurant/urls.py index 60db218..40e7a76 100644 --- a/pure_plate/restaurant/urls.py +++ b/pure_plate/restaurant/urls.py @@ -3,8 +3,6 @@ from . import views - - urlpatterns = [ - path('restaurants/',views.restaurants_in_categories_view, name='restaurants-in-categories') + path('list/',views.restaurants_list, name='restaurants-list') ] \ No newline at end of file diff --git a/pure_plate/restaurant/views.py b/pure_plate/restaurant/views.py index 9f9b6f9..84d4667 100644 --- a/pure_plate/restaurant/views.py +++ b/pure_plate/restaurant/views.py @@ -2,49 +2,26 @@ from django.db.models import Count from .models import Restaurant -#/api/restaurants_in_categories?categories=Italian,Chinese,Mexican - -def restaurants_in_categories_view(request): +def restaurants_list(request): try: - category_names = request.GET.get('categories', '') - if not category_names: - return JsonResponse({ - 'status': 200, - 'message': 'Category is not selected.', - 'data': [] - }) - - category_names_list = category_names.split(',') - - filter_conditions = {} - if 'vegan' in category_names_list: - filter_conditions['vegan'] = True - if 'halal' in category_names_list: - filter_conditions['halal'] = True - if 'glutenfree' in category_names_list: - filter_conditions['gluten_free'] = True - if 'lactofree' in category_names_list: - filter_conditions['lacto_free'] = True - - restaurants = Restaurant.objects.filter(**filter_conditions) - - + restaurants = Restaurant.objects.all() + data = [{ - 'restaurantId': restaurant.id, - 'restaurantName': restaurant.name, - 'restaurantAddress': restaurant.address, - 'restaurantLatitude': str(restaurant.latitude), - 'restaurantLongitude': str(restaurant.longitude), - 'restaurantTime': restaurant.time, - 'restaurantPhoto': restaurant.photo, - 'restaurantPhone': restaurant.phone, - 'restaurantReviewCount': restaurant.review_count, - 'restaurantRating': str(restaurant.avg_rating), - 'restaurantVegan': restaurant.vegan, - 'restaurantHalal': restaurant.halal, - 'restaurantGlutenFree': restaurant.gluten_free, - 'restaurantLactoFree': restaurant.lacto_free + 'Id': restaurant.id, + 'Name': restaurant.name, + 'Address': restaurant.address, + 'Latitude': str(restaurant.latitude), + 'Longitude': str(restaurant.longitude), + 'Time': restaurant.time, + 'Photo': restaurant.photo, + 'Phone': restaurant.phone, + 'ReviewCount': restaurant.review_count, + 'Rating': str(restaurant.avg_rating), + 'Vegan': restaurant.vegan, + 'Halal': restaurant.halal, + 'GlutenFree': restaurant.gluten_free, + 'LactoFree': restaurant.lacto_free } for restaurant in restaurants] @@ -54,10 +31,10 @@ def restaurants_in_categories_view(request): 'data': data } - return JsonResponse(response) + return JsonResponse(response, status=200) except Exception as e: - return JsonResponse({'status': 400, 'message': str(e), 'data': []}) + return JsonResponse({'status': 400, 'message': str(e), 'data': []}, status=400)