class AbstractAttachment(models.Model): name = models.CharField(max_length=255, null=True, blank=True, help_text="Defaults to filename, if left blank") file = models.FileField( upload_to=get_attachment_upload_to(), storage=get_attachment_storage() ) uploaded = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name class Meta: abstract = True
class AbstractAttachment(models.Model): name = models.CharField(max_length=255, null=True, blank=True, help_text="Defaults to filename, if left blank") file = models.FileField(upload_to=get_attachment_upload_to(), storage=get_attachment_storage()) uploaded = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name def save(self, *args, **kwargs): if not self.name: self.name = self.file.name super(AbstractAttachment, self).save(*args, **kwargs) class Meta: abstract = True
class Migration(migrations.Migration): dependencies = [ ('boards', '0015_auto_20180725_0105'), ] operations = [ migrations.CreateModel( name='Attachment', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(blank=True, help_text='Defaults to filename, if left blank', max_length=255, null=True)), ('file', models.FileField(upload_to=get_attachment_upload_to())), ('uploaded', models.DateTimeField(auto_now_add=True)), ('size', models.IntegerField(null=True)), ('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='boards.Article')), ], options={ 'abstract': False, }, ), ]