djangodjango-adminmany-to-manydjango-multiwidget

Use multiwidget for many to many field with readonly additional data


I've the following models:

class Exam(models.Model):
    participants = models.ManyToMany(settings.AUTH_USER_MODEL, through='Participation')

class Participation(models.Model)
    user = models.OneToOneField(settings.AUTH_USER_MODEL)
    exam = models.ForeignKey('Exam')
    specific_number = models.PositiveIntegerField(editable=False)

As you can see, the data I'm storing in intermediary model is readonly. It's generated automatically by the system when an instance is created. So I'd like to be able to use the multiwidget in admin to select the participants. (Using inline is really hard when you have a large number of users). Is there anyway to do it?


Solution

  • The only way I found was to use a new view for managing participants in the admin and add a link to it by overriding the default edit template.