dzhuang / django-galleryfield

Django GalleryField with AJAX form widgets for multiple images upload with progress bar and arbitrarily ordering.
MIT License
34 stars 6 forks source link

Help Request: Can't get the form to work in forms or in admin #65

Open ShmuelTreiger opened 1 month ago

ShmuelTreiger commented 1 month ago

Hi!

I'm trying to integrate this project into mine, but I can't get it to work. I've spent a few hours reading the documentation and I'm at a loss. I can only get html to show up on my pages. This is from my admin:

image

My files:

home.py:

<imports>
from galleryfield.fields import GalleryField

class Home(BaseModel):
    images = GalleryField(blank=True, null=True)
   <other fields>

admin.py:

<imports>

class HomeAdminForm(GalleryFormMediaMixin, forms.ModelForm):
    class Meta:
        model = Home
        exclude = ()

class HomeAdmin(GISModelAdmin): //doesn't work with normal admin either
    form = HomeAdminForm

admin.site.register(Home, HomeAdmin)
admin.site.register(BuiltInGalleryImage)

settings.py

MEDIA_URL = "media/"
MEDIA_ROOT = BASE_DIR / "media/"
DJANGO_GALLERY_FIELD_CONFIG = {
    # You may change the value to 4 or 5 to see the results
    "bootstrap_version": 5, //doesn't work with 3, 4, or 5
}

My home form is also not working, it displays more or less the same as my admin:

class HomeForm(forms.ModelForm):
    class Meta:
        model = Home
        fields = [
            "images",
            <...>
       ]

        widgets = {
            "images": GalleryWidget, //I've tried with and without
        }

In my html I just added:

                    <div class="form-group">
                        {{ form.images.label_tag }} {{ form.images }}
                    </div>

My html header contains, in this order:

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
          integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

I'll also note that pip freeze contains django-galleryfield==2.2.0

Would appreciate any help, I've

dzhuang commented 1 month ago

Sorry for my late response. I am on a trip journey and will be back next week. I'll try to figure out your issue then.

ShmuelTreiger commented 1 month ago

No worries. Appreciate any help you might give. Hope you have a fun trip!