Skip to content

Commit

Permalink
Added model and admin for recommendations.
Browse files Browse the repository at this point in the history
  • Loading branch information
abecam committed Jan 29, 2024
1 parent 0bd097b commit dc62bc2
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 3 deletions.
34 changes: 32 additions & 2 deletions thefiltershop/filtershop_main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
),
]
Original file line number Diff line number Diff line change
@@ -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')),
],
),
]
Original file line number Diff line number Diff line change
@@ -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')),
],
),
]
21 changes: 21 additions & 0 deletions thefiltershop/filtershop_main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="right-side">
<!-- TBD -->
<h2>See recommandations from</h2>
<h2>See recommendations from</h2>
<div class="link-right-side">
<a href="{% url 'filtershop_games:indies_games' %}" class="a_link-right-side">Our curators</a>
</div>
Expand Down

0 comments on commit dc62bc2

Please sign in to comment.