[Answer]-Add a field to Mezzanine blogpost

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
👤Mingo

0👍

You can create a django app (CustomBlog), add it to your installed apps
and remove or comment the Mezzanine blog:

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

In the models.py and admin.py, of your CustomBlog, inherit from the class BlogPost of Mezzanine:

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)

Then in the terminal create and run migrations

python manage.py makemigrations
python manage.py migrate

Leave a comment