Giter Site home page Giter Site logo

Comments (3)

matthewwithanm avatar matthewwithanm commented on August 22, 2024

@lettertwo just asked me about this so I thought I'd let everybody know my thoughts—and let you (@nishimu) know that I'm not ignoring you!

There is definitely a use-case for this; #11 is an example. Having said that, I'm not sure I'm a fan of allowing a processors callable. The reason is that I can see a new issue being created in two months in which somebody says, "we should make the format argument a callable." And quality. Basically, the rationale for allowing processors to be a callable would be the same for every other field—including ones that we may add in the future. Furthermore, in practice, the functions used for these values would have to repeat much of the same work—in other words, what determines which processors are used is also likely to determine the format. To have to execute the same code twice is gross.

I think the idea of a callable "processors" argument may be too narrow of a solution. What you (and @koebbe) want, in effect, is to define different specs based on properties of the model. I'm still trying to figure out if there's a way to do that that fits with how we're used to working with Django fields. Ultimately, the answer may just be to allow callables for all the arguments, but I want to see if we can't come up with something better first.

Anybody have any good ideas for alternatives here? Or examples of Django libraries with fields that change behavior based on model properties?

from django-imagekit.

jokerejoker avatar jokerejoker commented on August 22, 2024

How about making it posible to define the ImageSpec inside the init of the model after the super init?

from django-imagekit.

matthewwithanm avatar matthewwithanm commented on August 22, 2024

Sorry for dragging my feet on this one.

@jokerejoker Unfortunately, model fields don't really work like that. In the case of ImageSpec, we could probably get it to work, but I think the result would be without precedent and tie our hands in the future if we need to do more bookkeeping in the contribute_to_class method.

Ultimately, I think that the best option we have (or at least the best one we've been able to come up with!) is to allow callables to be used for the processors argument. And, lucky for us, @cyberdelia has done that work for us in #85! I've pulled his changes into develop with commit 3bac472.

@nishimu Sorry again for dragging my feet so long on this solution (only to finally settle on what you suggested initially). I still have my original objections but the perfect is the enemy of the good, and we've gone long enough without a solution.

from django-imagekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.