Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango admin many-to-many intermediary models using through= and filter_horizontal
    primarykey
    data
    text
    <p>This is how my models look:</p> <pre><code>class QuestionTagM2M(models.Model): tag = models.ForeignKey('Tag') question = models.ForeignKey('Question') date_added = models.DateTimeField(auto_now_add=True) class Tag(models.Model): description = models.CharField(max_length=100, unique=True) class Question(models.Model): tags = models.ManyToManyField(Tag, through=QuestionTagM2M, related_name='questions') </code></pre> <p>All I really wanted to do was add a timestamp when a given manytomany relationship was created. It makes sense, but it also adds a bit of complexity. Apart from removing the .add() functionality [despite the fact that the only field I'm really adding is auto-created so it technically shouldn't interfere with this anymore]. But I can live with that, as I don't mind doing the extra <code>QuestionTagM2M.objects.create(question=,tag=)</code> instead if it means gaining the additional timestamp functionality. My issue is I really would love to be able to preserve my <code>filter_horizontal</code> javascript widget in the admin. I know the docs say I can use an inline instead, but this is just too unwieldy because there are no additional fields that would actually be in the inline apart from the foreign key to the <code>Tag</code> anyway. Also, in the larger scheme of my database schema, my <code>Question</code> objects are already displayed as an inline on my admin page, and since Django doesn't support nested inlines in the admin [yet], I have no way of selecting tags for a given question. Is there any way to override <code>formfield_for_manytomany(self, db_field, request=None, **kwargs)</code> or something similar to allow for my usage of the nifty <code>filter_horizontal</code> widget and the auto creation of the <code>date_added</code> column to the database? This seems like something that django should be able to do natively as long as you specify that all columns in the intermediate are automatically created (other than the foreign keys) perhaps with <code>auto_created=True</code>? or something of the like</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload