Django类管理员逻辑错误

时间:2018-08-27 04:32:57

标签: django

我试图在Django admin中进行一些更改,这让我感到非常困惑,因为似乎我犯了某种大的基本逻辑错误。

我的错误是:

<class 'foodordering.admin.CInline'>: (admin.E202) 'foodordering.Customer' has no ForeignKey to 'foodordering.Order'.
<class 'foodordering.admin.DInline'>: (admin.E202) 'foodordering.Deliveryboy' has no ForeignKey to 'foodordering.Order'.
<class 'foodordering.admin.DishInline'>: (admin.E202) 'foodordering.Dish' has no ForeignKey to 'foodordering.Menu'.
<class 'foodordering.admin.DishInline'>: (admin.E202) 'foodordering.Dish' has no ForeignKey to 'foodordering.Order_dish'.
<class 'foodordering.admin.MenuAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'name', which is not a callable, an attribute of 'MenuAdmin', or an attribute or method on 'foodordering.Menu'.
<class 'foodordering.admin.MenuAdmin'>: (admin.E112) The value of 'list_filter' must be a list or tuple.
<class 'foodordering.admin.ODAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'name', which is not a callable, an attribute of 'ODAdmin', or an attribute or method on 'foodordering.Order_dish'.
<class 'foodordering.admin.ODAdmin'>: (admin.E108) The value of 'list_display[1]' refers to 'delivery', which is not a callable, an attribute of 'ODAdmin', or an attribute or method on 'foodordering.Order_dish'.
<class 'foodordering.admin.ODAdmin'>: (admin.E108) The value of 'list_display[3]' refers to 'status', which is not a callable, an attribute of 'ODAdmin', or an attribute or method on 'foodordering.Order_dish'.
<class 'foodordering.admin.ODAdmin'>: (admin.E108) The value of 'list_display[4]' refers to 'grade', which is not a callable, an attribute of 'ODAdmin', or an attribute or method on 'foodordering.Order_dish'.
<class 'foodordering.admin.ODAdmin'>: (admin.E108) The value of 'list_display[5]' refers to 'lastname', which is not a callable, an attribute of 'ODAdmin', or an attribute or method on 'foodordering.Order_dish'.
<class 'foodordering.admin.ODAdmin'>: (admin.E108) The value of 'list_display[6]' refers to 'postcode', which is not a callable, an attribute of 'ODAdmin', or an attribute or method on 'foodordering.Order_dish'.
<class 'foodordering.admin.ODAdmin'>: (admin.E108) The value of 'list_display[7]' refers to 'phonenumber', which is not a callable, an attribute of 'ODAdmin', or an attribute or method on 'foodordering.Order_dish'.
<class 'foodordering.admin.ODAdmin'>: (admin.E116) The value of 'list_filter[0]' refers to 'postcode', which does not refer to a Field.
<class 'foodordering.admin.OrderAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'name', which is not a callable, an attribute of 'OrderAdmin', or an attribute or method on 'foodordering.Order'.
<class 'foodordering.admin.OrderAdmin'>: (admin.E108) The value of 'list_display[1]' refers to 'availability', which is not a callable, an attribute of 'OrderAdmin', or an attribute or method on 'foodordering.Order'.
<class 'foodordering.admin.OrderAdmin'>: (admin.E108) The value of 'list_display[2]' refers to 'grade', which is not a callable, an attribute of 'OrderAdmin', or an attribute or method on 'foodordering.Order'.
<class 'foodordering.admin.OrderAdmin'>: (admin.E108) The value of 'list_display[3]' refers to 'currentlocation', which is not a callable, an attribute of 'OrderAdmin', or an attribute or method on 'foodordering.Order'.
<class 'foodordering.admin.OrderAdmin'>: (admin.E116) The value of 'list_filter[0]' refers to 'availability', which does not refer to a Field.
<class 'foodordering.admin.OrderInline'>: (admin.E202) 'foodordering.Order' has no ForeignKey to 'foodordering.Order_dish'.

foodordering / model.py:

from django.db import models

VIP_CHOICES = (
    ('normal','NORMAL'),
    ('vip', 'VIP'),
    ('vvip','VVIP'),
)

STATUS_CHOICES = (
    ('preparing', 'PREPARING'),
    ('delivering', 'DELIVERING'),
    ('ready to collect', 'READY TO COLLECT'),
)

class Customer(models.Model):
    firstname = models.CharField(max_length=20)
    lastname = models.CharField(max_length=20)
    address = models.CharField(max_length=200)
    address2 = models.CharField(max_length=200)
    address3 = models.CharField(max_length=200)
    postcode = models.IntegerField()
    dateofbirth = models.DateField()
    email = models.EmailField()
    phonenumber = models.IntegerField()
    grade = models.CharField(max_length=6, choices=VIP_CHOICES, default='normal')


class Deliveryboy(models.Model):
    name = models.CharField(max_length=100, default=None)
    currentlocation = models.CharField(max_length=100, default='Restaurant')
    availability = models.BooleanField


class Order(models.Model):
    delivery = models.BooleanField
    status = models.CharField(max_length=200, choices=STATUS_CHOICES, default='Preparing')
    DeliveryboyID = models.ForeignKey(Deliveryboy, on_delete=models.CASCADE)
    CustomerID = models.ForeignKey(Customer, on_delete=models.CASCADE)


class Dish(models.Model):
    name = models.CharField(max_length=100)


class Menu(models.Model):
    category = models.CharField(max_length=50)
    DishID = models.ForeignKey(Dish, on_delete=models.CASCADE)


class Order_dish(models.Model):
    quantity = models.IntegerField()
    OrderID = models.ForeignKey(Order, on_delete=models.CASCADE)
    DishID = models.ForeignKey(Dish, on_delete=models.CASCADE)

foodordering / admin.py:

from django.contrib import admin
from .models import Customer, Deliveryboy, Order, Menu, Dish, Order_dish


class CInline(admin.TabularInline):
    model = Customer
    extra = 2

class DInline(admin.TabularInline):
    model = Deliveryboy
    extra = 2

class OrderAdmin(admin.ModelAdmin):
    inlines = [CInline, DInline]
    list_filter = ['availability']
    list_display = ('name', 'availability', 'grade', 'currentlocation')
    search_fields = ['name', 'availability', 'grade', 'currentlocation']

class DishInline(admin.TabularInline):
    model = Dish
    extra = 2

class MenuAdmin(admin.ModelAdmin):
    inlines = [DishInline]
    search_fields = ['category']
    list_display = ('name', 'category')
    list_filter = ('name')

class OrderInline(admin.TabularInline):
    model = Order
    extra = 2

class ODAdmin(admin.ModelAdmin):
    inlines = [OrderInline, DishInline]
    list_display = ('name', 'delivery', 'quantity', 'status', 'grade', 'lastname', 'postcode', 'phonenumber')
    list_filter = ['postcode']
    search_fields = ['name', 'grade', 'lastname', 'postcode', 'phonenumber']

admin.site.register(Customer)
admin.site.register(Deliveryboy)
admin.site.register(Order, OrderAdmin)
admin.site.register(Menu, MenuAdmin)
admin.site.register(Dish)
admin.site.register(Order_dish, ODAdmin)

我想做的是当我在每个表中添加详细信息时让多个表通过外键连接,而实际上我很慌了..哈哈

非常感谢您的帮助。

0 个答案:

没有答案