Added voucher model.
This commit is contained in:
parent
a2412e88d2
commit
8d15610ca2
@ -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)
|
||||
|
@ -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')
|
||||
|
22
lostplaces/lostplaces_app/migrations/0005_voucher.py
Normal file
22
lostplaces/lostplaces_app/migrations/0005_voucher.py
Normal file
@ -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()),
|
||||
],
|
||||
),
|
||||
]
|
@ -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),
|
||||
),
|
||||
]
|
@ -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),
|
||||
),
|
||||
]
|
@ -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),
|
||||
),
|
||||
]
|
@ -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:
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user