tags:

views:

80

answers:

1

The docs say:

When you specify an intermediary model using the through argument to a ManyToManyField, the admin will not display a widget by default.

OK, but how about if I want a multiple select widget?

I have a model:

class Quotation(models.Model):
 source    = models.CharField()
 sourceLink  = models.URLField( blank=True)
 text   = models.TextField()
 site   = models.ManyToManyField(Site, through="QuoteSite" )

and an intermediary model:

class QuoteSite(models.Model):
 entry    = models.ForeignKey(Quotation)
 site   = models.ForeignKey(Site)
 dateLastUsed = models.DateField(default=date(2000,01,01))

All I want to do is allow users in admin to select one or more sites for their quotation. I don't care whether they can edit the datelastUsed field in the intermediary model.

Is this impossible?

A: 

I solved my problem by defining the 'site' m2m field without the 'through', instead specifying the same db_table as used by the QuoteSite class. Because I retrieve my 'TodaysQuote()' using a manager on the QuoteSite class, not the Quotation class, it turns out there's no reason for the Quotation class to know about the dateLastUsed at all.