From 0852e35b57e61eac3c0072e4b8c4f228e29b57bc Mon Sep 17 00:00:00 2001 From: Leonhard Strohmidel Date: Fri, 1 Oct 2021 09:28:45 +0200 Subject: [PATCH] #42 Level for Users --- .../migrations/0007_auto_20211001_0648.py | 44 +++++++++++++++++++ .../migrations/0008_explorer_level.py | 18 ++++++++ django_lostplaces/lostplaces/models/models.py | 13 ++++++ 3 files changed, 75 insertions(+) create mode 100644 django_lostplaces/lostplaces/migrations/0007_auto_20211001_0648.py create mode 100644 django_lostplaces/lostplaces/migrations/0008_explorer_level.py diff --git a/django_lostplaces/lostplaces/migrations/0007_auto_20211001_0648.py b/django_lostplaces/lostplaces/migrations/0007_auto_20211001_0648.py new file mode 100644 index 0000000..c0449aa --- /dev/null +++ b/django_lostplaces/lostplaces/migrations/0007_auto_20211001_0648.py @@ -0,0 +1,44 @@ +# Generated by Django 3.1.1 on 2021-10-01 06:48 + +from django.db import migrations, models +import django.db.models.deletion +import easy_thumbnails.fields +import lostplaces.models.place + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0006_merge_0004_release_0_1_3_0005_add_visited_places'), + ] + + operations = [ + migrations.AddField( + model_name='explorer', + name='favorite_places', + field=models.ManyToManyField(blank=True, related_name='explorer_favorites', to='lostplaces.Place', verbose_name='Explorers favorite places'), + ), + migrations.AddField( + model_name='place', + name='hero', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='place_heros', to='lostplaces.placeimage'), + ), + migrations.AlterField( + model_name='placeimage', + name='filename', + field=easy_thumbnails.fields.ThumbnailerImageField(help_text='Optional: One or more images to upload', upload_to=lostplaces.models.place.generate_place_image_filename, verbose_name='Images'), + ), + migrations.CreateModel( + name='DummyAsset', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('submitted_when', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Submission date')), + ('name', models.CharField(max_length=50)), + ('place', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='dummyassets', to='lostplaces.place')), + ('submitted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dummyassets', to='lostplaces.explorer', verbose_name='Submitter')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/django_lostplaces/lostplaces/migrations/0008_explorer_level.py b/django_lostplaces/lostplaces/migrations/0008_explorer_level.py new file mode 100644 index 0000000..c3bc42a --- /dev/null +++ b/django_lostplaces/lostplaces/migrations/0008_explorer_level.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.1 on 2021-10-01 06:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0007_auto_20211001_0648'), + ] + + operations = [ + migrations.AddField( + model_name='explorer', + name='level', + field=models.IntegerField(choices=[(1, 'Newbie'), (2, 'Scout'), (3, 'Explorer'), (4, 'Journalist'), (5, 'Housekeeper')], default=1), + ), + ] diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index d771f00..5f0fd44 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -29,6 +29,14 @@ def generate_profile_image_filename(instance, filename): return 'explorers/' + str(instance.user.pk) + '-' + str(instance.user.username) + '.' + filename.split('.')[-1] +EXPLORER_LEVELS = ( + (1, 'Newbie'), + (2, 'Scout'), + (3, 'Explorer'), + (4, 'Journalist'), + (5, 'Housekeeper') +) + class Explorer(models.Model): """ Profile that is linked to the Django user. @@ -69,6 +77,11 @@ class Explorer(models.Model): blank=True ) + level = models.IntegerField( + default=1, + choices=EXPLORER_LEVELS + ) + def __str__(self): return self.user.username