diff --git a/lostplaces/lostplaces_app/admin.py b/lostplaces/lostplaces_app/admin.py index e9d0a10..6016d15 100644 --- a/lostplaces/lostplaces_app/admin.py +++ b/lostplaces/lostplaces_app/admin.py @@ -9,7 +9,6 @@ from django.contrib.auth.admin import UserAdmin from .models import * from .forms import ExplorerCreationForm, ExplorerChangeForm -from .models import Explorer # Register your models here. @@ -20,5 +19,6 @@ class ExplorerAdmin(UserAdmin): list_display = ['email', 'username',] admin.site.register(Explorer, ExplorerAdmin) +admin.site.register(Voucher) admin.site.register(Place) admin.site.register(PlaceImage) diff --git a/lostplaces/lostplaces_app/forms.py b/lostplaces/lostplaces_app/forms.py index 5ae594c..6c78036 100644 --- a/lostplaces/lostplaces_app/forms.py +++ b/lostplaces/lostplaces_app/forms.py @@ -5,7 +5,7 @@ from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm -from .models import Explorer, Place, PlaceImage +from .models import Explorer, Place, PlaceImage, Voucher class ExplorerCreationForm(UserCreationForm): class Meta: @@ -13,7 +13,6 @@ class ExplorerCreationForm(UserCreationForm): fields = ('username', 'email') class ExplorerChangeForm(UserChangeForm): - class Meta: model = Explorer fields = ('username', 'email') diff --git a/lostplaces/lostplaces_app/migrations/0005_voucher.py b/lostplaces/lostplaces_app/migrations/0005_voucher.py new file mode 100644 index 0000000..323451f --- /dev/null +++ b/lostplaces/lostplaces_app/migrations/0005_voucher.py @@ -0,0 +1,22 @@ +# Generated by Django 3.0.8 on 2020-08-01 10:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces_app', '0004_placeimage_submitted_by'), + ] + + operations = [ + migrations.CreateModel( + name='Voucher', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('code', models.CharField(max_length=10)), + ('created', models.DateField(auto_now_add=True)), + ('expires', models.DateField()), + ], + ), + ] diff --git a/lostplaces/lostplaces_app/migrations/0006_auto_20200801_1037.py b/lostplaces/lostplaces_app/migrations/0006_auto_20200801_1037.py new file mode 100644 index 0000000..f850cb3 --- /dev/null +++ b/lostplaces/lostplaces_app/migrations/0006_auto_20200801_1037.py @@ -0,0 +1,22 @@ +# Generated by Django 3.0.8 on 2020-08-01 10:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces_app', '0005_voucher'), + ] + + operations = [ + migrations.RemoveField( + model_name='voucher', + name='id', + ), + migrations.AlterField( + model_name='voucher', + name='code', + field=models.CharField(max_length=10, primary_key=True, serialize=False, unique=True), + ), + ] diff --git a/lostplaces/lostplaces_app/migrations/0007_auto_20200801_1039.py b/lostplaces/lostplaces_app/migrations/0007_auto_20200801_1039.py new file mode 100644 index 0000000..93974fa --- /dev/null +++ b/lostplaces/lostplaces_app/migrations/0007_auto_20200801_1039.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.8 on 2020-08-01 10:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces_app', '0006_auto_20200801_1037'), + ] + + operations = [ + migrations.AlterField( + model_name='voucher', + name='created', + field=models.DateTimeField(auto_now_add=True), + ), + ] diff --git a/lostplaces/lostplaces_app/migrations/0008_auto_20200801_1044.py b/lostplaces/lostplaces_app/migrations/0008_auto_20200801_1044.py new file mode 100644 index 0000000..8161acb --- /dev/null +++ b/lostplaces/lostplaces_app/migrations/0008_auto_20200801_1044.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.8 on 2020-08-01 10:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces_app', '0007_auto_20200801_1039'), + ] + + operations = [ + migrations.AddField( + model_name='voucher', + name='id', + field=models.AutoField(auto_created=True, default=0, primary_key=True, serialize=False, verbose_name='ID'), + preserve_default=False, + ), + migrations.AlterField( + model_name='voucher', + name='code', + field=models.CharField(max_length=10, unique=True), + ), + ] diff --git a/lostplaces/lostplaces_app/models.py b/lostplaces/lostplaces_app/models.py index 11b8c2d..3be9545 100644 --- a/lostplaces/lostplaces_app/models.py +++ b/lostplaces/lostplaces_app/models.py @@ -22,6 +22,20 @@ class Explorer(AbstractUser): def __str__(self): return self.username +class Voucher(models.Model): + """ + Vouchers are authorization tokens to allow the registration of new users. + A voucher has a code, a creation and a deletion date, which are all positional. + Creation date is being set automatically during voucher creation. + """ + + code = models.CharField(unique=True, max_length=10) + created = models.DateTimeField(auto_now_add=True) + expires = models.DateField() + + def __str__(self): + return "Voucher " + str(self.pk) + class Place (models.Model): """ Place defines a lost place (location, name, description etc.). @@ -45,7 +59,7 @@ class Place (models.Model): def generate_image_upload_path(instance, filename): """ - Callback for generating path for uploaded images + Callback for generating path for uploaded images. """ return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1] @@ -87,7 +101,7 @@ class PlaceImage (models.Model): Returning the name of the corresponding place + id of this image as textual represntation of this instance """ - + return ' '.join([self.place.name, str(self.pk)]) # These two auto-delete files from filesystem when they are unneeded: diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index b13a6e5..b32dfc1 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -11,7 +11,7 @@ from django.http import Http404 from django.views.generic.edit import UpdateView from .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm -from .models import Place, PlaceImage +from .models import Place, PlaceImage, Voucher # Create your views here.