Re: FilteredSelectMultiple widget on field feincms content type

72 views
Skip to first unread message

Nelson Varela

unread,
Jan 30, 2013, 8:20:34 AM1/30/13
to django-...@googlegroups.com
In my own model field class, FileManyToMany, Add "def formfield(self, ...)" which adds the widget
from django.db import models
from feincms.module.medialibrary.models import MediaFile

class FileManyToMany(models.ManyToManyField):
    def __init__(self, to=MediaFile, **kwargs):
        limit = {'type__in': ['doc', 'pdf', 'xls']}
        limit.update(kwargs.get('limit_choices_to', {}))
        kwargs['limit_choices_to'] = limit
        super(FileManyToMany, self).__init__(to, **kwargs)

    def formfield(self, **kwargs):
        from django.contrib import admin
        defaults = {'widget': admin.widgets.FilteredSelectMultiple('vebose_name', False)}
        defaults.update(kwargs)
        return super(FileManyToMany, self).formfield(**defaults)

On Tuesday, January 29, 2013 11:13:23 AM UTC+1, Nelson Varela wrote:

I have a custom made content type in FeinCMS.

class DownloadsContent(models.Model):
    title = models.CharField(max_length=200, verbose_name=_('title'))
    files = FileManyToMany(verbose_name=_('files'))

The 'files' field is an manytomany which only shows .doc and .pdf files:

class FileManyToMany(models.ManyToManyField):
    def __init__(self, to=MediaFile, **kwargs):
        limit = {'type__in': ['doc', 'pdf']}
        limit.update(kwargs.get('limit_choices_to', {}))
        kwargs['limit_choices_to'] = limit
        super(FileManyToMany, self).__init__(to, **kwargs)

Untill now everything works fine. When adding this content type it shows all files.

But how can I make use of the django FilteredSelectMultiple widget in my content type?

http://stackoverflow.com/questions/14560955/filteredselectmultiple-widget-on-field-feincms-content-type

Reply all
Reply to author
Forward
0 new messages