django-filer and ManyToMany field

606 views
Skip to first unread message

Martin Kjellberg

unread,
Apr 14, 2014, 8:30:52 PM4/14/14
to django...@googlegroups.com
Hi!

First of all, thank you for a fantastic app! It made my life so much simpler in many cases! Gracias!

So, I'm having a model where I would like the file browser to be used (in the admin), but in a ManyToMany field. Simple example:


class Correspondence(models.Model):
    subject
= models.CharField(_('subject'), max_length=500)
    body
= models.TextField(_('body'))
    files
= models.ManyToManyField(** This should be the Filer field **)


How are you guys solving this scenario?

Thank you,
/Martin

Stefan Foulis

unread,
Apr 15, 2014, 4:20:01 AM4/15/14
to django...@googlegroups.com
Hi Martin

Thanks!
The trouble is, that there is no usable ManyToMany widget for filer (yet). What we've done in the past, is a ManyToMany with a custom "through" table (but no extra fields).
Then you can display it with a django.contrib.admin.TabularInlineAdmin.
If you don't now what I am talking about, I could dig out a code example from one of our projects. I just can't recall in what project we did that right now.

Cheers
Stefan


--
You received this message because you are subscribed to the Google Groups "django-filer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-filer...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Kjellberg

unread,
Apr 16, 2014, 12:08:47 PM4/16/14
to django...@googlegroups.com
Excellent Stefan!

I'll try that approach, thank you!

Marco Silva

unread,
Jan 8, 2016, 9:39:53 AM1/8/16
to django-filer
Hey!

Is this feature still in development? i would also like to use the filler models as a many to many, could you suply an example code as i had never used the "through" table?

Cheers
Marco Silva

Hassan Mian

unread,
Jul 24, 2017, 5:47:38 AM7/24/17
to django-filer
Hi Marco,

Please have a look at:


If we use Martins example the code would look something like this:

class Correspondence(models.Model):
    subject 
= models.CharField(_('subject'), max_length=500)
    body 
= models.TextField(_('body'))

    files 
= models.ManyToManyField(Attachment, through='CorrespondenceAttachment')

class Attachment(models.Model):
    content = FilerImageField()

class CorrespondenceAttachment(models.Model):
    correspondence = models.ForeignKey(Correspondence, on_delete=models.CASCADE)
    attachment = models.ForeignKey(Attachment, on_delete=models.CASCADE)
Reply all
Reply to author
Forward
0 new messages