# Path: della/gallery/models.py
# class Image(TimeStampMixin):
#     file = models.ImageField(upload_to='images/%Y/%m/%d')
#     title = models.CharField(max_length=300)
#     description = models.TextField(null=True)
#     added_by = models.ForeignKey(User, on_delete=models.CASCADE)


from django.forms import ModelForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Reset, Layout, Fieldset
from .models import Image



class ImageUploadForm(ModelForm):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # make description optional field
        self.fields['description'].required = False

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Fieldset(
                'Upload Image',
                'title',
                'file',
                'description'
            )
        )
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = 'gallery:upload'
        self.helper.label_class = 'col-lg-2'

# Path: della/gallery/models.py
# class Image(TimeStampMixin):
#     file = models.ImageField(upload_to='images/%Y/%m/%d')
#     title = models.CharField(max_length=300)
#     description = models.TextField(null=True)
#     added_by = models.ForeignKey(User, on_delete=models.CASCADE)


# Path: della/gallery/forms.py
from django.forms import ModelForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Reset, Layout, Fieldset
from .models import Image




class ImageUploadForm(ModelForm):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # make description optional field
        self.fields['description'].required = False

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Fieldset(
                'Upload Image',
                'title',
                'file',
                'description'
            )
        )
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = 'gallery:upload'
        self.helper.label_class = 'col-lg-2'

        self.helper.field_class = 'col-lg-10'