Answer the question
In order to leave comments, you need to log in
Django how to get data from related tables?
There are two models
class Building(models.Model):
name=models.CharField(max_length=32)
class Room(models.Model):
number=models.CharField(max_length=8)
building=models.ForeignKey(Building,on_delete=models.PROTECT)
class RoomEdit(admin.ModelAdmin):
list_display = ('number' 'showBuilding')
def showBuilding(self, obj):
return "\n".join([a.name for a in obj.building.all()])
class BuildingEdit(admin.ModelAdmin):
list_display = ('name' ..........)
def showBuilding(self, obj):
........
admin.site.register(Building, showBuilding)
admin.site.register(Room, RoomEdit)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question