0

I am using Mezzanine for a project. I need to add a extra field to Mezzanine blogpost.

I notice using EXTRA_MODEL_FIELDS can do it, but it looks complex.

I also try copy the blog folder from the site-package to my project path, and then modify the models.py. but I doesn't work.

I am new to Django, can some one help?

Thanks

Mingo
  • 1,613
  • 2
  • 16
  • 20

2 Answers2

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
  • 1,613
  • 2
  • 16
  • 20
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
César Villaseñor
  • 822
  • 1
  • 7
  • 15
  • Have you been able to successfully do this? I ask because I had some errors when I tried something similar, and then I saw in the docs a note saying that only subclassing `Page` was supported: http://mezzanine.jupo.org/docs/content-architecture.html#creating-custom-content-types – Elias Dorneles Oct 09 '20 at 15:50