﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34979	inlineformset_factory sets max_num forms to one even though there is a unique_together constraint	Evan Edward Hallein	nobody	"I have a unique_together primary key in one of my models.  When adding an inline admin for that model, the interface only allows adding one new object.  I have tracked it down to code in django/django/forms/models.py: 
{{{
fk = _get_foreign_key(parent_model, model, fk_name=fk_name)
    # enforce a max_num=1 when the foreign key to the parent model is unique.
    if fk.unique:
        max_num = 1
}}}

this is my model (autogenerated from an existing database):
class TrtMeasurements(models.Model):
    observation = models.OneToOneField('TrtObservations', models.DO_NOTHING, primary_key=True)
    measurement_type = models.ForeignKey(TrtMeasurementTypes, models.DO_NOTHING, db_column='measurement_type')
    measurement_value = models.FloatField()
    comments = models.TextField(blank=True, null=True)
    
    class Meta:
        managed = False
        db_table = 'trt_measurements'
        unique_together = (('observation', 'measurement_type'),)

While this makes sense for a single unique primary key, it is the wrong behavior for a composite primary key.

Is a fix needed in Django so multiple objects with unique_together primary keys can be added as inlines, or should this be done using custom code?"	Uncategorized	new	contrib.admin	3.2	Normal		inline admin		Unreviewed	0	0	0	0	0	1
