python - 在 Django 管理页面中,SubCatalog未显示

  显示原文与译文双语对照的内容
0 0

我正在创建一个 Django 应用程序,其中包含subcatalog的父目录,并且产品将沿subcatalog映射。 我正在将代码发布到下面,请帮助。


from django.db import models
from datetime import datetime
from django.forms import ModelForm
from django.contrib.auth.models import User

# Create your models here.

class Catalog(models.Model):
 name = models.CharField(max_length=300)
 slug = models.SlugField(max_length=150)
 publisher = models.CharField(max_length=300, blank=True)
 description = models.TextField()
 pub_date = models.DateTimeField(default=datetime.now)

 def __unicode__(self):
 return self.name

class SubCatalog(models.Model):
 catalog = models.ForeignKey(Catalog)
 name = models.CharField(max_length=300)
 slug = models.SlugField(max_length=150)
 description = models.TextField()
 pub_date = models.DateTimeField(default=datetime.now)

 def __unicode__(self):
 return self.name 

class Product(models.Model):
 catalog = models.ForeignKey(Catalog)
 subcatalog = models.ForeignKey(SubCatalog)
 name = models.CharField(max_length=300)
 slug = models.SlugField(max_length=150)
 description = models.TextField()
 photo = models.FileField(upload_to='product_photo', blank=True)
 manufacturer = models.CharField(max_length=300, blank=True)
 price_in_ksh = models.DecimalField(max_digits=6, decimal_places=0)

 def __unicode__(self):
 return self.name

时间: 原作者:

0 0

你需要在你的应用程序 admin.py 中使用 register SubCatalog:


admin.site.register(SubCatalog)

...