Ohad
Ohad

Reputation: 1480

Representing ManyToMany relation in the Admin Panel

I am trying to represent a ManyToMany relation in the Admin panel for the following models:

models.py

class Adress(models.Model):
    address = models.TextField()

class Person(models.Model):
   locations = models.ManyToManyField(Address)

admin.py

class PeronsAddressRelation(admin.TabularInline):
    model = models.Person.locations.through

class PersonInline(admin.TabularInline):
    model = models.Person
    inlines = [PeronsAddressRelation]

The problem now is that I have many relations so when loading the admin edit page of a Person, it takes a lot of time until the Admin view builds the select box of PersonAddressRelation .

Is there anyway I can show inside of PersonAddressInline the name of the address without it being inside a select box? (just static text with a Delete option).

Upvotes: 0

Views: 805

Answers (1)

bmihelac
bmihelac

Reputation: 6323

Check ModelAdmin.raw_id_fields. Using raw_id_fields will tell django admin not to create drop down menu.

Upvotes: 1

Related Questions