3

I have an intersection/through table being used as an inline in the django admin. The inline has the foreign key to the other model listed as a drop down menu. I am able to make the field read only by setting the readonly_fields variable, but wish to allow addition of new foreign key objects by adding. So with the example below I'd like to be able to add Building_Room rows via the inline, just not be able to choose from any existing Room keys without clicking the '+' and adding a new one via the Room pop up admin screen. Will I have to do this via custom template work? Thanks much.

models.py

class Building(models.Model):
    rooms = models.ManyToManyField('Room', null=True, through="Building_Room")
    ...
class Room(models.Model):
    ...
class Building_Room(models.Model):
    building = models.ForeignKey(Building)
    room = models.ForeignKey(Room)

admin.py

class Building_Room_Inline(admin.TabularInline):
    model = Building_Room
    readonly_fields = ('building',)
    ...
class Building_Admin(admin.ModelAdmin):
    inlines = (Building_Room_Inline,)
    ...
wilbbe01
  • 1,931
  • 1
  • 24
  • 38
  • I thought I'd searched, but looks like this might be my answer http://stackoverflow.com/questions/7860612/django-admin-make-field-editable-in-add-but-not-edit. My question is a possible duplicate :). Checking answer now. – wilbbe01 Oct 26 '11 at 00:45

0 Answers0