2013-03-11 45 views
0

我正在使用Mezzanine作爲項目。我需要爲Mezzanine blogpost添加一個額外的字段。添加一個字段給Mezzanine blogpost

我注意到使用EXTRA_MODEL_FIELDS可以做到,但看起來很複雜。

我也嘗試從網站包複製博客文件夾到我的項目路徑,然後修改models.py。但我不工作。

我是Django的新手,有人可以幫忙嗎?

感謝

回答

1
 
By do some research, now I got the answer: 
1. copy the blog app from sites-package to my project 
2. change my setting.py 
    INSTALLED_APPS = (
    "blog",  #it was "mezzanine.blog", 
    ..... 
3. modify the blog/models.py 
    add following line to class BlogPost 
    shop_url= models.CharField(max_length=250,null=True, blank=True) 
4. migirate the table (installed South) 
    ./manage.py schemamigration blog --auto 
    ./manage.py migrate blog 
0

您可以創建一個Django應用程序(CustomBlog),將其添加到您的安裝的應用程序 並刪除或註釋夾層博客:

INSTALLED_APPS = (
    "CustomBlog",  #it was "mezzanine.blog", 
    ... 
) 

在models.py和您的CustomBlog的admin.py繼承自Mezzanine的BlogPost類:

models.py 
from django.db import models 
from mezzanine.blog.models import BlogPost 
from mezzanine.blog.models import BlogCategory 


class CustomBlog(BlogPost): 
    # Add New Field 
    # example 
    new_field = models.CharField(max_length=255) 

class CustomBlogCategory(BlogCategory): 
    pass 

admin.py 
from django.contrib import admin 
from .models import CustomBlog,CustomBlogCategory 


admin.site.register(CustomBlog) 
admin.site.register(CustomBlogCategory) 

然後在終端上創建並運行遷移

python manage.py makemigrations 
python manage.py migrate