Skip to content

Commit

Permalink
Add RichtextArea field to GalleryCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Jun 18, 2024
1 parent 326f31a commit bbd7e3c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
13 changes: 11 additions & 2 deletions testapp/forms/gallerycollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from django.forms.models import ModelForm

from formset.collection import FormCollection
from formset.richtext.dialogs import SimpleLinkDialogForm
from formset.richtext.widgets import RichTextarea, controls
from formset.widgets import UploadedFileInput

from testapp.models.gallery import Image, Gallery


Expand All @@ -11,16 +14,22 @@ class ImageForm(ModelForm):
required=False,
widget=widgets.HiddenInput,
)

image = fields.FileField(
label="Image",
widget=UploadedFileInput,
required=False,
)
caption = fields.CharField(
label="Caption",
required=False,
widget=RichTextarea(
#attrs={'use_json': True},
)
)

class Meta:
model = Image
fields = ['id', 'image']
fields = ['id', 'image', 'caption']


class ImageCollection(FormCollection):
Expand Down
1 change: 1 addition & 0 deletions testapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.FileField(blank=True, upload_to='images')),
('caption', formset.richtext.fields.RichTextField(blank=True, null=True)),
('gallery', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images', to='testapp.gallery')),
],
),
Expand Down
8 changes: 6 additions & 2 deletions testapp/models/gallery.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from django.db import models

from formset.richtext.fields import RichTextField


class Gallery(models.Model):
name = models.CharField(
verbose_name="Gallery name",
max_length=50,
)

created_by = models.CharField(
editable=False,
max_length=40,
Expand All @@ -27,7 +28,10 @@ class Image(models.Model):
upload_to='images',
blank=True,
)

caption = RichTextField(
blank=True,
null=True,
)
gallery = models.ForeignKey(
Gallery,
on_delete=models.CASCADE,
Expand Down

0 comments on commit bbd7e3c

Please sign in to comment.