Recommended way to add additional fields to media files?

35 views
Skip to first unread message

googlegroups

unread,
May 14, 2012, 7:30:46 PM5/14/12
to Django FeinCMS
Hia,

I want media files to have additional fields, e.g. another CharField
field (translatable, similar to 'caption') and another Integer field
(non-translatable, similar to file_size). What's the recommended way
to implement this? Read: The most elegant, least coupling way. Through
MediaFile.register_extensions('myext'), given that MediaFileBase
inherits from ExtensionsMixin? If so (or not so), could you give an
example for the fields mentioned above?

What other code adjustments would be required due these additions
(e.g. zip import/export, admin (probably taken care of in the
extension already), ..) and what are the recommended ways to implement
these adjustments?

Cheers

Dani

googlegroups

unread,
May 18, 2012, 9:42:07 PM5/18/12
to Django FeinCMS
Re,

would appreciate getting a response from any of the knowledgeable
FeinCMS devs as I couldn't find any hints on this.

Thanks

Dani

Martin J. Laubach

unread,
May 19, 2012, 4:45:33 AM5/19/12
to django-...@googlegroups.com
For the non-translatable fields, an extension is certainly the way to go. However, you're probably going to run into trouble with that functionality that expects a certain set of fields (like the zip export/import, I have absolutely no idea how it will cope).

For the translatable fields, I don't really have a good answer. Since the translations are off in another table altogether, I'm not sure there is an easy way of extending that. Matthias?

Cheers,

mjl

googlegroups

unread,
May 20, 2012, 7:51:08 PM5/20/12
to django-...@googlegroups.com
Thanks, Martin. I think I'd definitely have to extend the zip export/import functionality too, somehow (as disabling this functionality is not an option for me).

I'm still wondering though whether there are any elegant solutions I'm not aware of (and whether it's possible at all, without forking?). Matthias (and/or Simon)?

Cheers

Dani

Matthias Kestenholz

unread,
May 21, 2012, 12:24:20 PM5/21/12
to django-...@googlegroups.com
On Mon, May 21, 2012 at 1:51 AM, googlegroups <gmai...@numlock.ch> wrote:
> Thanks, Martin. I think I'd definitely have to extend the zip export/import
> functionality too, somehow (as disabling this functionality is not an option
> for me).
>
> I'm still wondering though whether there are any elegant solutions I'm not
> aware of (and whether it's possible at all, without forking?). Matthias
> (and/or Simon)?

It's not easily possible ATM. I didn't occur to me to use extensions
with mediafiles to be honest.

If you get a hold onto the MediaFile class, you can always access the
translation class using:

In [1]: from feincms.module.medialibrary.models import *

In [2]: MediaFile.translations.related.model
Out[2]: feincms.module.medialibrary.models.MediaFileTranslation


(Maybe we could add a creativecommons extension which offers a few
fields for specifying the licensing terms directly in the media
library, and not only with the copyright field?)


Matthias

Martin J. Laubach

unread,
May 21, 2012, 2:41:02 PM5/21/12
to django-...@googlegroups.com
Thanks, Martin. I think I'd definitely have to extend the zip export/import functionality too, somehow

The whole export/import thing was not really built with extensibility in mind, and I'd be happy to add whatever hooks you need to make it better!

mjl


 

googlegroups

unread,
Jun 19, 2012, 11:59:17 AM6/19/12
to Django FeinCMS
Thanks for the hint, Matthias.

In the end, I went with non-translatable field extensions only (which
turned out to be sufficient).

Regarding the coupling with import_zipfile/export_zipfile, it might be
possible to generalize the serialization/deserialization routines
through introspection. Haven't had the time yet though to look into
it.

Cheers

Dani

On 21 Mai, 18:24, Matthias Kestenholz <m...@feinheit.ch> wrote:
Reply all
Reply to author
Forward
0 new messages