我的应用程序中有各种模型。但是,有一个我无法注册,所以我可以在admin panel.所以在我的cart应用程序admin.py文件中,我可以使用:from django.contrib import adminfrom .models import Cart, CartItem# Register your models here.admin.site.register(Cart)但不是:from django.contrib import adminfrom .models import Cart, CartItem# Register your models here.admin.site.register(Cart, CartItem)因为我收到此错误: File "/home/ogonzales/Escritorio/projects_envs/perfectcushion_env/lib/python3.6/site-packages/django/contrib/admin/checks.py", line 26, in check_admin_app errors.extend(site.check(app_configs)) File "/home/ogonzales/Escritorio/projects_envs/perfectcushion_env/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 81, in check if modeladmin.model._meta.app_config in app_configs:AttributeError: 'CartItem' object has no attribute 'model'购物车/models.py:from django.db import modelsfrom shop.models import Product# Create your models here.class Cart(models.Model): cart_id = models.CharField(max_length=250, blank=True) date_added = models.DateField(auto_now_add=True) class Meta: db_table = 'Cart' ordering = ['date_added'] def __str__(self): return self.cart_idclass CartItem(models.Model): product = models.ForeignKey(Product, on_delete=models.CASCADE) cart = models.ForeignKey(Cart, on_delete=models.CASCADE) quantity = models.IntegerField() active = models.BooleanField(default=True) class Meta: db_table = 'CartItem' def sub_total(self): return self.product.price * self.quantity def __str__(self): return self.product
添加回答
举报
0/150
提交
取消