mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fiexed #3055 -- Validate that models target of a GenericRelation have a GenericForeignKey field.
Thanks jason for diagnosing the problem and Marcos Moyano for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14563 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import sys
|
||||
|
||||
from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation
|
||||
from django.core.management.color import color_style
|
||||
from django.utils.itercompat import is_iterable
|
||||
|
||||
try:
|
||||
any
|
||||
except NameError:
|
||||
from django.utils.itercompat import any
|
||||
|
||||
class ModelErrorCollection:
|
||||
def __init__(self, outfile=sys.stdout):
|
||||
self.errors = []
|
||||
@@ -224,6 +231,12 @@ def get_validation_errors(outfile, app=None):
|
||||
e.add(opts, "'%s' specifies an m2m relation through model %s, "
|
||||
"which has not been installed" % (f.name, f.rel.through)
|
||||
)
|
||||
elif isinstance(f, GenericRelation):
|
||||
if not any([isinstance(vfield, GenericForeignKey) for vfield in f.rel.to._meta.virtual_fields]):
|
||||
e.add(opts, "Model '%s' must have a GenericForeignKey in "
|
||||
"order to create a GenericRelation that points to it."
|
||||
% f.rel.to.__name__
|
||||
)
|
||||
|
||||
rel_opts = f.rel.to._meta
|
||||
rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name()
|
||||
|
||||
Reference in New Issue
Block a user