diff --git a/roms/forms.py b/roms/forms.py new file mode 100644 index 0000000..93e1f39 --- /dev/null +++ b/roms/forms.py @@ -0,0 +1,9 @@ +from django.forms import ModelForm + +from roms.models import Rom + + +class RomUploadForm(ModelForm) + class Meta: + model = Rom + fields = ['name', 'description', 'cover', 'low_binary', 'high_binary', 'tags'] diff --git a/roms/migrations/0004_auto_20170508_2136.py b/roms/migrations/0004_auto_20170508_2136.py new file mode 100644 index 0000000..8273960 --- /dev/null +++ b/roms/migrations/0004_auto_20170508_2136.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.6 on 2017-05-08 21:36 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone +import roms.models +import stdimage.models +import stdimage.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('roms', '0003_auto_20170506_2213'), + ] + + operations = [ + migrations.AddField( + model_name='rom', + name='creation_time', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='creation time'), + preserve_default=False, + ), + migrations.AddField( + model_name='rom', + name='edit_time', + field=models.DateTimeField(auto_now=True, verbose_name='edit time'), + ), + migrations.AlterField( + model_name='rom', + name='cover', + field=stdimage.models.StdImageField(upload_to=roms.models.upload_cover_to, validators=[stdimage.validators.MinSizeValidator(300, 300)], verbose_name='cover image'), + ), + migrations.AlterField( + model_name='rom', + name='name', + field=models.CharField(max_length=128, unique=True, verbose_name='name'), + ), + ] diff --git a/roms/models.py b/roms/models.py index bb107a9..5c78ca3 100644 --- a/roms/models.py +++ b/roms/models.py @@ -18,17 +18,20 @@ def upload_binary_to(instance, filename): class Rom(models.Model): - name = models.CharField("name", max_length = 128) + name = models.CharField("name", max_length = 128, unique=True) description = models.TextField("description") cover = StdImageField("cover image", upload_to = upload_cover_to, validators = [MinSizeValidator(300,300)], variations = {'large': {'width': 600, 'height': 600, 'crop': True}, 'small': {'width': 300, 'height': 300, 'crop': True}}) - low_binary = models.FileField("low binary", upload_to=upload_binary_to) - high_binary = models.FileField("high binary", upload_to=upload_binary_to) + low_binary = models.FileField("low binary", upload_to = upload_binary_to) + high_binary = models.FileField("high binary", upload_to = upload_binary_to) approved = models.BooleanField("approved") tags = TaggableManager(blank = True) + creation_time = models.DateTimeField("creation time", auto_now_add = True) + edit_time = models.DateTimeField("edit time", auto_now = True) + def tag_list(self): return [t.name for t in self.tags.all()]