views:

366

answers:

2

I've essentially got two tables: Page(PK=url) and PageProperty(PK=url+name).

Here is how I have my Models set up:

class Page(model.Model):
    url   = model.CharField(primary_key=True, max_length=255, db_column='url')
    #.....

class PageProperty(model.Model):
    # table with compound key (url + name)
    url   = model.ForeignKey('Page', to_field='url', db_column='url', primary_key=True)
    name  = model.CharField(primary_key=True, max_length=20)
    value = model.TextField()

I have a ModelAdmin set up so I can Inline edit PageProperty(s) from Page. Its a legacy database and I know there's a lot of data in there. But the Admin is only showing ONE of the PagePropertys, not all.

A: 

I think you might need to apply the extra option to your TabularInline. Example:

class PagePropertyInline(admin.TabularInline):
    model = PageProperty
    extra = 3

You could probably do some magic to make the amount of extra items dynamic (such as the number of PageProperty objects for a given Page, but I'll leave that up to you.

I would suggest further reading on InlineModelAdmin options and Formsets.

jathanism
thanks, but the 'extra' property is to control how many empty rows to show for NEW records.
Off Rhoden
I was pretty sure it applied to display of formsets as well, but it is also possible that may have smoked too much crack.
jathanism
A: 

Because it felt as thought a non-integer primary key was too much against the grain, I ended up buckling down and migrating the schema to use an auto generated integer pk for both tables. After that everything was smooth sailing again and the Inlines worked perfectly.

Off Rhoden