mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-26 09:34:50 +00:00
Use Django 1.8 meta API in Page.copy()
Fall back to old API for Django 1.7
This commit is contained in:
parent
e8510af03a
commit
ae691f7ed0
1 changed files with 20 additions and 2 deletions
|
|
@ -5,6 +5,7 @@ import json
|
|||
|
||||
from modelcluster.models import ClusterableModel, get_all_child_relations
|
||||
|
||||
import django
|
||||
from django.db import models, connection, transaction
|
||||
from django.db.models import Q
|
||||
from django.db.models.signals import post_save, pre_delete, post_delete
|
||||
|
|
@ -769,9 +770,26 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
|
|||
specific_self = self.specific
|
||||
specific_dict = {}
|
||||
|
||||
for field in specific_self._meta.fields:
|
||||
if field.name not in exclude_fields and not (field.rel is not None and field.rel.parent_link):
|
||||
if django.VERSION >= (1, 8):
|
||||
for field in specific_self._meta.get_fields():
|
||||
# Ignore explicitly excluded fields
|
||||
if field.name in exclude_fields:
|
||||
continue
|
||||
|
||||
# Ignore reverse relations
|
||||
if field.auto_created:
|
||||
continue
|
||||
|
||||
# Ignore parent links (page_ptr)
|
||||
if isinstance(field, models.OneToOneField) and field.parent_link:
|
||||
continue
|
||||
|
||||
specific_dict[field.name] = getattr(specific_self, field.name)
|
||||
else:
|
||||
# Django 1.7
|
||||
for field in specific_self._meta.fields:
|
||||
if field.name not in exclude_fields and not (field.rel is not None and field.rel.parent_link):
|
||||
specific_dict[field.name] = getattr(specific_self, field.name)
|
||||
|
||||
# New instance from prepared dict values, in case the instance class implements multiple levels inheritance
|
||||
page_copy = self.specific_class(**specific_dict)
|
||||
|
|
|
|||
Loading…
Reference in a new issue