Django Admin,显示相关的表字段

时间:2014-10-31 20:08:42

标签: django django-admin

对于Django中的Admin界面,我有一个名为RideInfo的类,其中包含属性。我有另一个名为Rider的类,它通过外键与RideInfo相关。这是RideInfo和Ride之间的1 - 许多关系。 Admin.py如下所示:

from django.contrib.gis import admin
from django.contrib.gis.admin import OSMGeoAdmin
from models import Bike, RideInfo, Rider

class BikeInline(admin.TabularInline):
    model = RideInfo
    extra = 0

class BikeAdmin(OSMGeoAdmin):
    inlines = [BikeInline]

admin.site.register(Bike,BikeAdmin) 

如何在管理界面中显示Rider中的字段?

models.py

导入日期时间     来自django.contrib.gis.db导入模型     来自django.utils导入时区

class Bike(models.Model):
    name = models.CharField(max_length=50)  
    geom = models.PointField(srid=4326)
    latLonBoundingBox = models.CharField(max_length=50)  
    objects = models.GeoManager()
    def __str__(self):
        return self.name

class RideInfo(models.Model):
    rideSpots = models.ForeignKey(Bike)
    rideTypeMTB = models.CharField('Downhill/XC/Freeride', max_length=100)
    ridetime = models.DateTimeField('Ride Time')
    roadOrDirt = models.CharField('Road or Dirt', max_length=100)
    rideLevel = models.CharField('Ride Difficulty', max_length=100)
    objects = models.GeoManager()

class Rider(models.Model):
    rider = models.ForeignKey(RideInfo)
    riderRidingWhere = models.ForeignKey(Bike)
    riderName = models.CharField('Rider Name', max_length=100)
    objects = models.GeoManager()

# Auto-generated `LayerMapping` dictionary for bike_hud model
bike_hud_mapping = {
    'name' : 'Name',
    'geom' : 'POINT',
}

0 个答案:

没有答案