diff --git a/newsaggregator/core/__pycache__/__init__.cpython-310.pyc b/newsaggregator/core/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..70040fe Binary files /dev/null and b/newsaggregator/core/__pycache__/__init__.cpython-310.pyc differ diff --git a/newsaggregator/core/__pycache__/admin.cpython-310.pyc b/newsaggregator/core/__pycache__/admin.cpython-310.pyc new file mode 100644 index 0000000..df1873a Binary files /dev/null and b/newsaggregator/core/__pycache__/admin.cpython-310.pyc differ diff --git a/newsaggregator/core/__pycache__/apps.cpython-310.pyc b/newsaggregator/core/__pycache__/apps.cpython-310.pyc new file mode 100644 index 0000000..98ca375 Binary files /dev/null and b/newsaggregator/core/__pycache__/apps.cpython-310.pyc differ diff --git a/newsaggregator/core/__pycache__/forms.cpython-310.pyc b/newsaggregator/core/__pycache__/forms.cpython-310.pyc new file mode 100644 index 0000000..b2204f1 Binary files /dev/null and b/newsaggregator/core/__pycache__/forms.cpython-310.pyc differ diff --git a/newsaggregator/core/__pycache__/models.cpython-310.pyc b/newsaggregator/core/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..98d1386 Binary files /dev/null and b/newsaggregator/core/__pycache__/models.cpython-310.pyc differ diff --git a/newsaggregator/core/__pycache__/urls.cpython-310.pyc b/newsaggregator/core/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..a6c2ff3 Binary files /dev/null and b/newsaggregator/core/__pycache__/urls.cpython-310.pyc differ diff --git a/newsaggregator/core/__pycache__/views.cpython-310.pyc b/newsaggregator/core/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..48d7d1f Binary files /dev/null and b/newsaggregator/core/__pycache__/views.cpython-310.pyc differ diff --git a/newsaggregator/core/admin.py b/newsaggregator/core/admin.py index ebf32b9..2686b6f 100644 --- a/newsaggregator/core/admin.py +++ b/newsaggregator/core/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from core.models import Headline,Bookmark,Contact +from core.models import Headline, Bookmark, Contact admin.site.register(Headline) admin.site.register(Bookmark) admin.site.register(Contact) diff --git a/newsaggregator/core/migrations/0004_alter_rating_headline.py b/newsaggregator/core/migrations/0004_alter_rating_headline.py new file mode 100644 index 0000000..aa2c853 --- /dev/null +++ b/newsaggregator/core/migrations/0004_alter_rating_headline.py @@ -0,0 +1,19 @@ +# Generated by Django 5.0.6 on 2024-06-23 05:24 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0003_headline_average_rating_headline_rating_count_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='rating', + name='headline', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ratings', to='core.headline'), + ), + ] diff --git a/newsaggregator/core/migrations/__pycache__/0001_initial.cpython-310.pyc b/newsaggregator/core/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 0000000..17a65f6 Binary files /dev/null and b/newsaggregator/core/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/newsaggregator/core/migrations/__pycache__/0002_contact.cpython-310.pyc b/newsaggregator/core/migrations/__pycache__/0002_contact.cpython-310.pyc new file mode 100644 index 0000000..fa3375a Binary files /dev/null and b/newsaggregator/core/migrations/__pycache__/0002_contact.cpython-310.pyc differ diff --git a/newsaggregator/core/migrations/__pycache__/0003_headline_average_rating_headline_rating_count_and_more.cpython-310.pyc b/newsaggregator/core/migrations/__pycache__/0003_headline_average_rating_headline_rating_count_and_more.cpython-310.pyc new file mode 100644 index 0000000..54253f4 Binary files /dev/null and b/newsaggregator/core/migrations/__pycache__/0003_headline_average_rating_headline_rating_count_and_more.cpython-310.pyc differ diff --git a/newsaggregator/core/migrations/__pycache__/0004_alter_rating_headline.cpython-310.pyc b/newsaggregator/core/migrations/__pycache__/0004_alter_rating_headline.cpython-310.pyc new file mode 100644 index 0000000..f606322 Binary files /dev/null and b/newsaggregator/core/migrations/__pycache__/0004_alter_rating_headline.cpython-310.pyc differ diff --git a/newsaggregator/core/migrations/__pycache__/__init__.cpython-310.pyc b/newsaggregator/core/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..37d1744 Binary files /dev/null and b/newsaggregator/core/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/newsaggregator/core/models.py b/newsaggregator/core/models.py index 64adb0d..2b00c6d 100644 --- a/newsaggregator/core/models.py +++ b/newsaggregator/core/models.py @@ -26,7 +26,8 @@ class Headline(models.Model): average_rating = models.FloatField(default=0, null=True, blank=True) rating_count = models.IntegerField(default=0) def __str__(self): - return self.title + return f'{self.id} -> {self.title}' + class Bookmark(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) @@ -39,11 +40,11 @@ def __str__(self): # stores all the rating given by all the users class Rating(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) - headline = models.ForeignKey(Headline, on_delete=models.CASCADE) + headline = models.ForeignKey(Headline, on_delete=models.CASCADE, related_name="ratings") rating = models.IntegerField(choices=[(i, str(i)) for i in range(1, 6)], null=True, blank=True) def __str__(self): - return f"{self.user} rated {self.headline.title} as {self.rating}" + return f"{self.id} -> ({self.user}) rated {self.headline.id} ({self.headline.title}) as {self.rating}" diff --git a/newsaggregator/core/views.py b/newsaggregator/core/views.py index a3d5241..f2ffa28 100644 --- a/newsaggregator/core/views.py +++ b/newsaggregator/core/views.py @@ -234,8 +234,7 @@ def rate_headline(request, headline_id): headline.rating_count = ratings.count() headline.average_rating = sum(r.rating for r in ratings) / headline.rating_count if headline.rating_count > 0 else 0 headline.save() - - return JsonResponse({'status': 'success', 'average_rating': headline.average_rating, 'rating_count': headline.rating_count}) + return JsonResponse({'status': 'success', 'average_rating': round(headline.average_rating, 2), 'rating_count': headline.rating_count}) return JsonResponse({'status': 'fail'}, status=400) diff --git a/newsaggregator/db.sqlite3 b/newsaggregator/db.sqlite3 index 50fd8e3..22cfd7b 100644 Binary files a/newsaggregator/db.sqlite3 and b/newsaggregator/db.sqlite3 differ diff --git a/newsaggregator/newsaggregator/__pycache__/__init__.cpython-310.pyc b/newsaggregator/newsaggregator/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..4be723c Binary files /dev/null and b/newsaggregator/newsaggregator/__pycache__/__init__.cpython-310.pyc differ diff --git a/newsaggregator/newsaggregator/__pycache__/settings.cpython-310.pyc b/newsaggregator/newsaggregator/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..6d5ad9c Binary files /dev/null and b/newsaggregator/newsaggregator/__pycache__/settings.cpython-310.pyc differ diff --git a/newsaggregator/newsaggregator/__pycache__/urls.cpython-310.pyc b/newsaggregator/newsaggregator/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..67c37aa Binary files /dev/null and b/newsaggregator/newsaggregator/__pycache__/urls.cpython-310.pyc differ diff --git a/newsaggregator/newsaggregator/__pycache__/wsgi.cpython-310.pyc b/newsaggregator/newsaggregator/__pycache__/wsgi.cpython-310.pyc new file mode 100644 index 0000000..13583d3 Binary files /dev/null and b/newsaggregator/newsaggregator/__pycache__/wsgi.cpython-310.pyc differ diff --git a/newsaggregator/templates/components/news.html b/newsaggregator/templates/components/news.html index b198099..56b6e8a 100644 --- a/newsaggregator/templates/components/news.html +++ b/newsaggregator/templates/components/news.html @@ -28,20 +28,20 @@