我遇到了这个问题,我无法以某种方式解决。
所以我在Django 1.7.7上运行两个应用程序,模型如下
order.OrderItinerary(m2m through table)
itinerary.Itinerary
这里的问题是,当我在OrderItinerary中使用指向行程模型的外键时,它可以工作。 但是当Photo中的外键指向Itinerary模型时,它会引发我的错误
<class 'itinerary.admin.ItineraryPhotoAdmin'>: (admin.E108) The value of 'list_display[1]' refers to 'itinerary', which is not a callable, an attribute of 'ItineraryPhotoAdmin', or an attribute or method on 'itinerary.Photo'.
我只是不知道指向同一模型的两个不同模型如何能给我不同的结果
class Order(GenericModel):
def __str__(self):
return "%s" %(self.title)
title = models.CharField(max_length=64)
description = models.TextField(blank=True)
order_number= models.CharField(max_length=64, unique=True, blank=True, default='')
itineraries = models.ManyToManyField('itinerary.Itinerary', through='order.OrderItinerary')
第二种模式
class OrderItinerary(GenericModel):
title = models.CharField(max_length=64)
description = models.TextField(blank=True)
rating = models.FloatField(blank=True)
order = models.ForeignKey('order.Order')
itinerary = models.ForeignKey('itinerary.Itinerary')
第三种模式
class Itinerary(GenericModel):
uuid = models.CharField(max_length=128, default=generate_uuid)
title = models.CharField(max_length=64)
description = models.TextField(blank=True)
price = models.DecimalField(blank=True, null=True, decimal_places=2, max_digits=5)
total_rating= models.FloatField(default=0)
rating_num = models.IntegerField(default=0, verbose_name="number of customers rated")
第四种模式
class Photo(GenericModel):
caption = models.CharField(max_length=254, default='', blank=True)
photo = models.ImageField(upload_to=generate_photo_name)
itinenary = models.ForeignKey('itinerary.Itinerary', related_name="itinerary_photo")
答案 0 :(得分:3)
您的Photo
模型中有拼写错误,正确itinenary
至itinerary
。