我现在出错了。这是一个内联错误,我试图找到解决方案,并且整天都在尝试,但是失败了。我很抱歉这个问题是否很容易重复。
这是错误,当我尝试使用内联时显示
<class 'brick.admin.AdminRoomStateInline'>: (admin.E202)
'brick.RoomInfomation' has no ForeignKey to 'brick.RoomInfomation'
models.py
class RoomInfomation(models.Model):
roomNum = models.PositiveSmallIntegerField(default=0, primary_key=True)
roomFloor = models.PositiveSmallIntegerField(default=0)
startPointX = models.PositiveSmallIntegerField(default=0)
startPointY = models.PositiveSmallIntegerField(default=0)
#referencing
userInfo_RoomReservationFK = models.ForeignKey('UserInfo', null=True, blank=True)
compInfo_RoomInfoFK = models.ForeignKey('CompanyInfomations', on_delete=models.CASCADE)
companyRoomTypeInfo_RoomInfoFK = models.ForeignKey('CompanyRoomTypeInfomations', on_delete=models.CASCADE)
def __unicode__(self):
return '%s' % str(self.PositiveSmallIntegerField)
class RoomState(models.Model):
roomReservation_roomStateFK = models.ForeignKey('RoomInfomation')
reservationBlock = models.BooleanField(default=False)
reservated = models.BooleanField(default=False)
reservatedDate = models.DateField(blank=True, null=True)
reservationFirstDate = models.DateField(blank=True, null=True)
reservationEndDate = models.DateField(blank=True, null=True)
checkoutTime = models.DateField(blank=True, null=True)
checkinTime = models.DateField(blank=True, null=True)
admin.py
class AdminRoomStateInline(admin.TabularInline):
model = RoomInfomation
extra = 8
# list_display = [
# 'roomReservation_roomStateFK',
# 'reservationBlock',
# 'reservated',
# 'reservatedDate',#예약을 진행했던 날짜
# 'reservationFirstDate',
# 'reservationEndDate',
# 'checkoutTime',
# 'checkinTime',
# ]
# inlines = [AdminRoomInfomationInline,]
class AdminRoomInfomation(admin.ModelAdmin):
fields = [
'compInfo_RoomInfoFK',
'companyRoomTypeInfo_RoomInfoFK',
'userInfo_RoomReservationFK',
'startPointX',
'startPointY',
'roomNum',
'roomFloor'
]
inlines = [AdminRoomStateInline,]
#class RoomState(admin,ModelAdmin):
#admin.site.register(RoomInfomation)
#admin.site.register(RoomState, AdminRoomState)
admin.site.register(UserInfo, AdminUserInfo)
admin.site.register(RoomInfomation, AdminRoomInfomation)
admin.site.register(RoomState)
我仔细检查了可能无法尝试的内容,例如当我更改内联时
class AdminRoomState
到
class AdminRoomInfomationInline
错误
<class 'brick.admin.AdminRoomStateInline'>: (admin.E202)
'brick.RoomInfomation' has no ForeignKey to 'brick.RoomState'
答案 0 :(得分:0)
在AdminRoomStateInline
中,您正在传递RoomInformation
模型,该模型应该为`RoomState。