Dynamic list of ImageSpecField in a model?

35 zobrazení
Preskočiť na prvú neprečítanú správu

Thomas Alisi

neprečítané,
4. 9. 2015, 8:45:354. 9. 2015
komu: Django ImageKit
hey

so I would like to define a set of specs in my django settings, like

THUMBS = (640, 480, 360, 240)

then create as many ImageSpecField in my model as the number of values I define in THUMBS

I'm thinking of possible ways to implement it:

- override my model's __init__ and attach a set of ImageSpecFields (or maybe register a set of generators?)

- define a metaclass that would create the set of ImageSpecFields when __new__ is called, then extend my model with the metaclass, kind of scary to think of Django's Model class interactions...

none of these I'm really happy with, so any advise / suggestion you may have it would be greatly appreciated. trying to search on stackoverflow and here, but couldn't find anything similar

many thanks

Thomas Alisi

neprečítané,
7. 9. 2015, 8:17:517. 9. 2015
komu: Django ImageKit
no takers? :)

Bala Subramanyam Vemu

neprečítané,
9. 9. 2015, 10:31:519. 9. 2015
komu: Django ImageKit
Hi Thomas

The following did the trick for me

class user_specified_spec(ImageSpec):
def __init__(self,user_source, user_processor):
self.format = 'JPEG'
self.source = user_source
# like all image specs
self.options = {'quality': settings.IMAGEQUALITY}
# list of processors in a spec
self.processors = user_processor
register.generator('xxx:xxxx:xxxx', user_specified_spec)

Let me know if it works for you


Thanks
Bala

Thomas Alisi

neprečítané,
11. 9. 2015, 4:27:2811. 9. 2015
komu: django-...@googlegroups.com
oh, that looks good! for the time being I've just implemented a list of fields, statically, but I'll def. give this a go, will post results here as soon as I have updates

thanks Bala!

--
You received this message because you are subscribed to a topic in the Google Groups "Django ImageKit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-imagekit/iTe5U_sj9z0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-imagek...@googlegroups.com.
To post to this group, send email to django-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-imagekit/64369e07-1f1c-49ca-a644-1aeaa375aac4%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Odpovedať všetkým
Odpovedať autorovi
Poslať ďalej
0 nových správ