Package: django-smartfields
Django Model Fields that are smart.This app introduces a declarative way of handling fields’ values. It can be
especially useful when one field depends on a value from another field, even if
a field depends on itself. At first it might sound useless, but, as it turns
out, it is an amazing concept that helps in writing clear, concise and DRY code.Best way to describe is on a simple example. Let’s say there is a field where
you store a custom html page and you would like to have another field attached
to the same model store the same page but with html tags stripped out, moreover
you would like it to update whenever the first field changes it’s value. A
common way to handle that issue is to overwrite model’ssavemethod and put
all the logic there, right? What if you could just give a field a function that
does the stripping and everything else is taking care of? Wouldn’t that be nice,
huh?  Well, that’s one of many things this app let’s you do.Another great example is django’sImageFieldthat can updatewidth_fieldandheight_fieldwhenever image is changed. This app uses similar concepts
to achive that functionality. But here is a more powerful example that
demonstrates the value of this app. Let’s say you would like to have a user be
able to upload an image in any format and automatically add another version of
this image converted to JPEG and shrunk to fit in a box size of 1024x768. Here
is how it could look with utilization ofdjango-smartfields:fromdjango.dbimportmodelsfromsmartfieldsimportfieldsfromsmartfields.dependenciesimportFileDependencyfromsmartfields.processorsimportImageProcessorclassUser(models.Model):# ... more fields ....avatar=fields.ImageField(upload_to='avatar',dependencies=[FileDependency(attname='avatar_jpeg',processor=ImageProcessor(format='JPEG',scale={'max_width':1024,'max_height':768})),])avatar_jpeg=fields.ImageField(upload_to='avatar')# ... more fields ...That’s it. Did I mention that it will also clean up old files, when new ones are
uploaded?So, hopefully I got you convinced to give this app a try. There is full
documentation also on the way, but for now you can check out ‘tests’ folder for
some examples.Django settingsRequired django apps for most of the functionality:INSTALLED_APPS=['django.contrib.auth','django.contrib.sessions','django.contrib.contenttypes','django.contrib.sites','smartfields',# optional, needed for forms'crispy_forms']Other required settingsMIDDLEWARE=['django.contrib.sessions.middleware.SessionMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware']SITE_ID=1DependenciesDjangoversions >= 1.7 (also works for 2.x and 3.x)Python Pillow- (optional) used for
image conversion/resizing. AND/ORWand- (optional) also for image processing.ffmpeg- (optional) for video conversion. (can
be easily adopted foravconv).BeautifulSoup4- (optional)
for HTML strippinglxml- (optional) for BeautifulSoup.django-crispy-forms- (optional) for
ajax uploading.Plupload- (optional) for ajax uploading.Bootstrap3- (optional) for ajax uploading.Changelog1.1.3Addition ofCloudImageProcessorandCloudFFMEGPRocessor1.1.2Support for Django=3.1.*1.1.1Support for Django=3.0.*1.1.0renamedDependency.asynctoDependency.async_.
Fix for#16.
Thanks@zglennieFix compatibility withDjango=2.x:Addedapp_name='smartifelds'tourls.pyfileStop using_sizeand_set_size()attributes inNamedTemporaryFile,
since those where only available inDjango=1.x1.0.7addedgisfields.madelxmla default parser for HTMLProcessor.1.0.6addedRenameFileProcessor1.0.5minor bug fixes.1.0.4Switched to MIT LicenseAddedstashed_valueto processors.1.0.3Added support forWandwithWandImageProcessor.Made it compatible with Django 1.8Updated compiled JavaScript file.1.0.2Introducedpre_processor.MadeUploadToserializible.Got rid of custom handlers.Minor bugfixes.1.0.0Initial release