[Answered ]-With Django, representing foreignkeys in Admin

1👍

The problem is the missing ::

class HouseReport(admin.ModelAdmin):
                                   ^

Speaking about the task you’ve initially wanted to solve, check the InlineModelAdmin classes:

The admin interface has the ability to edit models on the same page as
a parent model. These are called inlines.

Add this to the admin.py:

from django.contrib import admin
from housing.models import HouseInformation, HouseReport


class HouseReportInline(admin.TabularInline):
    model = HouseReport

class HouseAdmin(admin.ModelAdmin):
    inlines = [
        HouseReportInline,
    ]

admin.site.register(HouseInformation, HouseAdmin)

And you will see the House information and all of the HouseReports associated with a House on the House admin page.

👤alecxe

1👍

You forgot the : after the class definition in line 5

class HouseReport(admin.ModelAdmin):

And you have to write

...
list_display = ('the_house',)
...

notice the trailing comma? It tells python, that it should create a tuple

👤wastl

Leave a comment