About the demo

The code in the demo seems simple, with only a model field galleryfield.fields.GalleryField used in demo.models to construct the gallery model. Actually, there are some logic fall behind the code.

Handling the image instances

Although we didn’t explicitly specify in the code, the demo is actually using built-in galleryfield.models.BuiltInGalleryImage as the image model for creating, listing, and updating images. The image model has 2 fields: a galleryfield.fields.GalleryField named image and an User field named creator. We think whatever it called, an User field is needed because that’s the basis for the server to determine the whether requested users are qualified to modify the image instances, or to view the image instances in a form listview, or to potentially delete existing image instances.

Further, If you look into galleryfield.urls and galleryfield.image_views, you will see 3 class-based views which are handling images (or image instances):

  • galleryfield.image_views.BuiltInImageCreateView for uploading images, requires login. Following the naming rule, The URL name is galleryfield-builtingalleryimage-upload.

  • galleryfield.image_views.BuiltInImageListView for fetching existing images, restricted to the owner of the images or superuser, with URL name galleryfield-builtingalleryimage-fetch.

  • and galleryfield.image_views.BuiltInImageCropView for server side cropping of uploaded images, restricted to the owner of the images or superuser, with URL name galleryfield-builtingalleryimage-crop.