My models contain many-to-many relationships. Measurements can be part of any number of DataSets .
# models.py from django.db import models class DataSet(models.Model): purpose = models.TextField() class Measurement(models.Model): value = models.IntegerField() sets = models.ManyToManyField(DataSet, null=True, blank=True, verbose_name="datasets this measurement appears in")
I want my admin interface to embed Measurement fields in the DataSet admin, for example, how TabularInline works with the ForeignKey field. This is what I still have:
Unfortunately, all I get is pop-ups with the β+β buttons next to them that open the Measurement admin. I want the actual field of the value dimension to be displayed in a row. I tried adding value to the list of fields in MeasurementInline:
# admin.py class MeasurementInline(admin.TabularInline): model = Measurement.sets.through fields = ['value']
But this gives me an error: 'MeasurementInline.fields' refers to field 'value' that is missing from the form. .
How can I open editable fields for Measurement in the admin DataSet ?
Notes: This is a simplified case; my real case has many fields in my Measurement model. It would be terribly tiring if people using the admin interface had to open a new window for entering data, especially since they would need to do some copying and pasting between the fields.
Even in my actual models, the data that I want users to edit inline does NOT describe the relationship between the DataSet and Measurement β only Measurement itself. I believe that this makes the intermediate model unsuitable for my purposes.
Steven T. Snyder
source share