# Path: db_file_storage/form_widgets.py
# class DBClearableFileInput(ClearableFileInput):
#     template_name = 'db_file_storage/widgets/clearable_file_input.html'
# 
# class DBAdminClearableFileInput(AdminFileWidget):
#     template_name = 'db_file_storage/widgets/admin_clearable_file_input.html'
# 
# Path: demo_and_tests/model_filefields_example/models.py
# class Book(models.Model):
#     book_pk = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=100, unique=True)
#     index = models.FileField(
#         upload_to='model_filefields_example.BookIndex/bytes/filename/mimetype',
#         blank=True, null=True
#     )
#     pages = models.FileField(
#         upload_to='model_filefields_example.BookPages/bytes/filename/mimetype',
#         blank=True, null=True
#     )
#     cover = models.ImageField(
#         upload_to='model_filefields_example.BookCover/bytes/filename/mimetype',
#         blank=True, null=True
#     )
# 
#     def get_absolute_url(self):
#         return reverse('model_files:book.edit', kwargs={'pk': self.pk})
# 
#     def save(self, *args, **kwargs):
#         delete_file_if_needed(self, 'index')
#         delete_file_if_needed(self, 'pages')
#         super(Book, self).save(*args, **kwargs)
# 
#     def delete(self, *args, **kwargs):
#         super(Book, self).delete(*args, **kwargs)
#         delete_file(self, 'index')
#         delete_file(self, 'pages')
# 
#     def __str__(self):
#         return self.name
# 
# class SoundDevice(models.Model):
#     name = models.CharField(max_length=100)
#     instruction_manual = models.FileField(
#         upload_to='model_filefields_example.SoundDeviceInstructionManual'
#                   '/bytes/filename/mimetype',
#         blank=True,
#         null=True
#     )


from django import forms
from django.contrib.admin.forms import forms as adminforms
from db_file_storage.form_widgets import DBClearableFileInput, \
    DBAdminClearableFileInput
from .models import Book, SoundDevice
# django
# third party
# project


class BookForm(forms.ModelForm):
    class Meta(object):
        model = Book
        exclude = []
        widgets = {
            'index': DBClearableFileInput,
            'pages': DBClearableFileInput,
            'cover': DBClearableFileInput,
        }


class BookAdminForm(adminforms.ModelForm):
    class Meta(object):
        model = Book
        exclude = []
        widgets = {
            'index': DBAdminClearableFileInput,
            'pages': DBAdminClearableFileInput,
            'cover': DBAdminClearableFileInput,
        }


class SoundDeviceForm(forms.ModelForm):
    class Meta(object):

# Path: db_file_storage/form_widgets.py
# class DBClearableFileInput(ClearableFileInput):
#     template_name = 'db_file_storage/widgets/clearable_file_input.html'
# 
# class DBAdminClearableFileInput(AdminFileWidget):
#     template_name = 'db_file_storage/widgets/admin_clearable_file_input.html'
# 
# Path: demo_and_tests/model_filefields_example/models.py
# class Book(models.Model):
#     book_pk = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=100, unique=True)
#     index = models.FileField(
#         upload_to='model_filefields_example.BookIndex/bytes/filename/mimetype',
#         blank=True, null=True
#     )
#     pages = models.FileField(
#         upload_to='model_filefields_example.BookPages/bytes/filename/mimetype',
#         blank=True, null=True
#     )
#     cover = models.ImageField(
#         upload_to='model_filefields_example.BookCover/bytes/filename/mimetype',
#         blank=True, null=True
#     )
# 
#     def get_absolute_url(self):
#         return reverse('model_files:book.edit', kwargs={'pk': self.pk})
# 
#     def save(self, *args, **kwargs):
#         delete_file_if_needed(self, 'index')
#         delete_file_if_needed(self, 'pages')
#         super(Book, self).save(*args, **kwargs)
# 
#     def delete(self, *args, **kwargs):
#         super(Book, self).delete(*args, **kwargs)
#         delete_file(self, 'index')
#         delete_file(self, 'pages')
# 
#     def __str__(self):
#         return self.name
# 
# class SoundDevice(models.Model):
#     name = models.CharField(max_length=100)
#     instruction_manual = models.FileField(
#         upload_to='model_filefields_example.SoundDeviceInstructionManual'
#                   '/bytes/filename/mimetype',
#         blank=True,
#         null=True
#     )


# Path: demo_and_tests/model_filefields_example/forms.py
from django import forms
from django.contrib.admin.forms import forms as adminforms
from db_file_storage.form_widgets import DBClearableFileInput, \
    DBAdminClearableFileInput
from .models import Book, SoundDevice

# django
# third party
# project


class BookForm(forms.ModelForm):
    class Meta(object):
        model = Book
        exclude = []
        widgets = {
            'index': DBClearableFileInput,
            'pages': DBClearableFileInput,
            'cover': DBClearableFileInput,
        }


class BookAdminForm(adminforms.ModelForm):
    class Meta(object):
        model = Book
        exclude = []
        widgets = {
            'index': DBAdminClearableFileInput,
            'pages': DBAdminClearableFileInput,
            'cover': DBAdminClearableFileInput,
        }


class SoundDeviceForm(forms.ModelForm):
    class Meta(object):

        model = SoundDevice