我正在创建一个django应用程序,其目录是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 :(得分:1)
您需要在应用SubCatalog
注册admin.py
:
admin.site.register(SubCatalog)