# Path: demo_and_tests/model_filefields_example/forms.py
# class BookForm(forms.ModelForm):
#     class Meta(object):
#         model = Book
#         exclude = []
#         widgets = {
#             'index': DBClearableFileInput,
#             'pages': DBClearableFileInput,
#             'cover': DBClearableFileInput,
#         }
# 
# class SoundDeviceForm(forms.ModelForm):
#     class Meta(object):
#         model = SoundDevice
#         exclude = []
# 
# 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: db_file_storage/compat.py

# 
# Path: db_file_storage/views.py
# def get_file(request, add_attachment_headers, extra_headers=None):


from django.views.generic import ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from .forms import BookForm, SoundDeviceForm
from .models import Book, SoundDevice
from db_file_storage.compat import url, reverse_lazy
from db_file_storage import views as db_file_storage_views
    url(
        r'^books/add/$',
        CreateView.as_view(
            model=Book,
            form_class=BookForm,
            template_name='model_filefields_example/book_form.html',
            success_url=reverse_lazy('model_files:book.list')
        ),
        name='book.add'
    ),
    url(
        r'^books/edit/(?P<pk>\d+)/$',
        UpdateView.as_view(
            model=Book,
            form_class=BookForm,
            template_name='model_filefields_example/book_form.html',
            success_url=reverse_lazy('model_files:book.list')
        ),
        name='book.edit'
    ),
    url(
        r'^books/delete/(?P<pk>\d+)/$',
        DeleteView.as_view(
            model=Book,
            success_url=reverse_lazy('model_files:book.list')
        ),
        name='book.delete'
    ),
    url(
        r'^book-cover-download/',

# Path: demo_and_tests/model_filefields_example/forms.py
# class BookForm(forms.ModelForm):
#     class Meta(object):
#         model = Book
#         exclude = []
#         widgets = {
#             'index': DBClearableFileInput,
#             'pages': DBClearableFileInput,
#             'cover': DBClearableFileInput,
#         }
# 
# class SoundDeviceForm(forms.ModelForm):
#     class Meta(object):
#         model = SoundDevice
#         exclude = []
# 
# 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: db_file_storage/compat.py

# 
# Path: db_file_storage/views.py
# def get_file(request, add_attachment_headers, extra_headers=None):


# Path: demo_and_tests/model_filefields_example/urls.py
from django.views.generic import ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from .forms import BookForm, SoundDeviceForm
from .models import Book, SoundDevice
from db_file_storage.compat import url, reverse_lazy
from db_file_storage import views as db_file_storage_views

    url(
        r'^books/add/$',
        CreateView.as_view(
            model=Book,
            form_class=BookForm,
            template_name='model_filefields_example/book_form.html',
            success_url=reverse_lazy('model_files:book.list')
        ),
        name='book.add'
    ),
    url(
        r'^books/edit/(?P<pk>\d+)/$',
        UpdateView.as_view(
            model=Book,
            form_class=BookForm,
            template_name='model_filefields_example/book_form.html',
            success_url=reverse_lazy('model_files:book.list')
        ),
        name='book.edit'
    ),
    url(
        r'^books/delete/(?P<pk>\d+)/$',
        DeleteView.as_view(
            model=Book,
            success_url=reverse_lazy('model_files:book.list')
        ),
        name='book.delete'
    ),
    url(
        r'^book-cover-download/',

        db_file_storage_views.get_file,