我正试图在南迁移中访问Flatpages模型,如下所示:
s = orm['flatpages.Site'].objects.get(id=10)
f = orm['flatpages.FlatPage'].objects.get(id=10)
我收到错误消息说平板应用中没有网站和平面网站模型。那么我做错了什么?
答案 0 :(得分:0)
您无法通过南方orm
对象访问它,但如果您只是想强制进行数据迁移,则可以中断建议并直接导入模型,例如,
from south.db import db
from south.v2 import DataMigration
from django.db import models
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
class Migration(DataMigration):
def forwards(self, orm):
site = Site.objects.get_current()
f = FlatPage.objects.create(
title="Page Name",
url="/url/",
content="..."
)
f.sites.add(site)
f.save()