From dc62bc239a0aff8f71af063f139f5552e4326672 Mon Sep 17 00:00:00 2001 From: Alain Date: Mon, 29 Jan 2024 12:32:13 +0100 Subject: [PATCH] Added model and admin for recommendations. --- thefiltershop/filtershop_main/admin.py | 34 +++++++++++++++++-- ...060_profile_contribution_level_and_more.py | 29 ++++++++++++++++ .../0061_recommended_games_by_sponsor.py | 22 ++++++++++++ .../0062_recommended_games_by_contributor.py | 22 ++++++++++++ thefiltershop/filtershop_main/models.py | 21 ++++++++++++ .../thefiltershop/right_column_games.html | 2 +- 6 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 thefiltershop/filtershop_main/migrations/0060_profile_contribution_level_and_more.py create mode 100644 thefiltershop/filtershop_main/migrations/0061_recommended_games_by_sponsor.py create mode 100644 thefiltershop/filtershop_main/migrations/0062_recommended_games_by_contributor.py diff --git a/thefiltershop/filtershop_main/admin.py b/thefiltershop/filtershop_main/admin.py index 36be3a7..2461729 100644 --- a/thefiltershop/filtershop_main/admin.py +++ b/thefiltershop/filtershop_main/admin.py @@ -33,9 +33,33 @@ class MyAdminSite(admin.AdminSite): admin_site = MyAdminSite(name='customadmin') -@admin.register(models.Profile, models.User, models.Group, site=admin_site) +class Recommended_Games_By_Sponsor(admin.TabularInline): + model = models.Recommended_Games_By_Sponsor + autocomplete_fields = ( + 'game', + ) + xtra = 2 + verbose_name = "Recommended game" + verbose_name_plural = "Recommended games" + +class Recommended_Games_By_Contributor(admin.TabularInline): + model = models.Recommended_Games_By_Contributor + autocomplete_fields = ( + 'game', + ) + xtra = 2 + verbose_name = "Recommended game" + verbose_name_plural = "Recommended games" + +@admin.register(models.Profile, site=admin_site) class ProfileAdmin(admin.ModelAdmin): + inlines = [Recommended_Games_By_Contributor] + exclude= ['number_of_contrib', 'last_changed_by'] + +@admin.register(models.User, models.Group, site=admin_site) +class USerGroupAdmin(admin.ModelAdmin): + exclude= ['last_changed_by'] @admin.register(models.TypeOfEntity, models.TypeOfRelationBetweenFilter, models.Entity_Category, models.Platform, models.Tag, site=admin_site) class GeneralAdmin(admin.ModelAdmin): @@ -55,7 +79,13 @@ def save_model(self, request, obj, form, change): search_fields = ["name"] exclude= ['last_changed_by'] -@admin.register(models.Publisher, models.Sponsor, +@admin.register(models.Sponsor, site=admin_site) +class Sponsor(GeneralAdmin): + inlines = [Recommended_Games_By_Sponsor] + list_display = ["name", "in_hall_of_shame"] + +inlines = [Recommended_Games_By_Contributor] +@admin.register(models.Publisher, models.Studio, site=admin_site) class ElementWithHallOfShame(GeneralAdmin): list_display = ["name", "in_hall_of_shame"] diff --git a/thefiltershop/filtershop_main/migrations/0060_profile_contribution_level_and_more.py b/thefiltershop/filtershop_main/migrations/0060_profile_contribution_level_and_more.py new file mode 100644 index 0000000..b152970 --- /dev/null +++ b/thefiltershop/filtershop_main/migrations/0060_profile_contribution_level_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.1 on 2024-01-29 09:22 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('filtershop_main', '0059_entity_description_hidden_full_cost'), + ] + + operations = [ + migrations.AddField( + model_name='profile', + name='contribution_level', + field=models.CharField(choices=[('RE', 'Regular user'), ('SU', 'Supporter'), ('SSU', 'Super Supporter')], default='RE', max_length=3), + ), + migrations.AlterField( + model_name='entity', + name='description_hidden_full_cost', + field=models.CharField(blank=True, help_text="A default text will be displayed otherwise, from 0 (none) to 100 (infinite: the product cannot be bought fully while it's possible to spend an infinite amoount of money.)", max_length=300, null=True, verbose_name='You can give a custom description for the hidden full cost of this product'), + ), + migrations.AlterField( + model_name='entity', + name='hidden_full_cost', + field=models.IntegerField(default=0, help_text='0 (none) to 50 (full price again (if not f2p)) to 80 (a lot more) to 100 (infinite, i.e. cannot be won whatever you spend)', validators=[django.core.validators.MaxValueValidator(100), django.core.validators.MinValueValidator(0)], verbose_name='Hidden full cost: 0 to 100'), + ), + ] diff --git a/thefiltershop/filtershop_main/migrations/0061_recommended_games_by_sponsor.py b/thefiltershop/filtershop_main/migrations/0061_recommended_games_by_sponsor.py new file mode 100644 index 0000000..54a7176 --- /dev/null +++ b/thefiltershop/filtershop_main/migrations/0061_recommended_games_by_sponsor.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.1 on 2024-01-29 10:13 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('filtershop_main', '0060_profile_contribution_level_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='Recommended_Games_By_Sponsor', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('game', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='filtershop_main.videogame_common')), + ('sponsor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='filtershop_main.sponsor')), + ], + ), + ] diff --git a/thefiltershop/filtershop_main/migrations/0062_recommended_games_by_contributor.py b/thefiltershop/filtershop_main/migrations/0062_recommended_games_by_contributor.py new file mode 100644 index 0000000..05393cc --- /dev/null +++ b/thefiltershop/filtershop_main/migrations/0062_recommended_games_by_contributor.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.1 on 2024-01-29 10:52 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('filtershop_main', '0061_recommended_games_by_sponsor'), + ] + + operations = [ + migrations.CreateModel( + name='Recommended_Games_By_Contributor', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('game', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='filtershop_main.videogame_common')), + ('sponsor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='filtershop_main.profile')), + ], + ), + ] diff --git a/thefiltershop/filtershop_main/models.py b/thefiltershop/filtershop_main/models.py index c1febeb..b897315 100644 --- a/thefiltershop/filtershop_main/models.py +++ b/thefiltershop/filtershop_main/models.py @@ -53,6 +53,17 @@ class TypeOfEntity(BaseModel): filters = models.ManyToManyField(Filter, blank=True) class Profile(BaseModel): + class ContributorLevel(models.TextChoices): + REGULAR = "RE", _("Regular user") + SUPPORTER = "SU", _("Supporter") + SUPER_SUPPORTER = "SSU", _("Super Supporter") + + contribution_level = models.CharField( + max_length=3, + choices=ContributorLevel.choices, + default=ContributorLevel.REGULAR, + ) + user = models.OneToOneField(User, on_delete=models.CASCADE) number_of_contrib = models.IntegerField(default=0) # Incremented when something is updated by the user. full_name = models.CharField(max_length=300) @@ -318,6 +329,16 @@ class Sponsor(BaseModel): in_hall_of_shame = models.BooleanField(default=False) descriptionOfShame = models.TextField(max_length=1000, null=True, blank=True) +## Sponsors and contributors can suggest games +class Recommended_Games_By_Sponsor(models.Model): + sponsor = models.ForeignKey(Sponsor, on_delete=models.CASCADE, null=False) + game = models.ForeignKey(Videogame_common, on_delete=models.CASCADE, null=False) + +## Sponsors and contributors can suggest games +class Recommended_Games_By_Contributor(models.Model): + sponsor = models.ForeignKey(Profile, on_delete=models.CASCADE, null=False) + game = models.ForeignKey(Videogame_common, on_delete=models.CASCADE, null=False) + class Company_group(Entity): company_logo = models.ImageField() diff --git a/thefiltershop/filtershop_main/templates/thefiltershop/right_column_games.html b/thefiltershop/filtershop_main/templates/thefiltershop/right_column_games.html index de1c0c6..6d10df3 100644 --- a/thefiltershop/filtershop_main/templates/thefiltershop/right_column_games.html +++ b/thefiltershop/filtershop_main/templates/thefiltershop/right_column_games.html @@ -1,6 +1,6 @@
-

See recommandations from

+

See recommendations from