Ticket #3055: ticket_30500_2.patch
File ticket_30500_2.patch, 3.4 KB (added by , 14 years ago) |
---|
-
django/core/management/validation.py
23 23 from django.db.models.loading import get_app_errors 24 24 from django.db.models.fields.related import RelatedObject 25 25 from django.db.models.deletion import SET_NULL, SET_DEFAULT 26 from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation 27 try: 28 any 29 except NameError: 30 from django.utils.itercompat import any 26 31 27 32 e = ModelErrorCollection(outfile) 28 33 … … 225 230 "which has not been installed" % (f.name, f.rel.through) 226 231 ) 227 232 233 elif isinstance(f, GenericRelation): 234 if not any([isinstance(vfield, GenericForeignKey) for vfield in f.rel.to._meta.virtual_fields]): 235 e.add(opts, "model '%s' must have a GenericForeignKey in order to create a GenericRelation." % f.rel.to.__name__) 236 228 237 rel_opts = f.rel.to._meta 229 238 rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name() 230 239 rel_query_name = f.related_query_name() -
django/utils/itercompat.py
37 37 if not item: 38 38 return False 39 39 return True 40 41 def any(iterable): 42 for item in iterable: 43 if item: 44 return True 45 return False -
tests/modeltests/invalid_models/models.py
5 5 """ 6 6 7 7 from django.db import models 8 from django.contrib.contenttypes import generic 8 9 9 10 class FieldErrors(models.Model): 10 11 charfield = models.CharField() … … 216 217 class InvalidSetDefault(models.Model): 217 218 fk = models.ForeignKey('self', on_delete=models.SET_DEFAULT) 218 219 220 class Tag(models.Model): 221 name = models.CharField("name", max_length=20) 219 222 223 class TaggedObject(models.Model): 224 object_id = models.PositiveIntegerField("Object ID") 225 tag = models.ForeignKey(Tag) 226 content_object = generic.GenericForeignKey() 227 228 class UserTaggedObject(models.Model): 229 object_tag = models.ForeignKey(TaggedObject) 230 231 class ArticleAttachment(models.Model): 232 tags = generic.GenericRelation(TaggedObject) 233 user_tags = generic.GenericRelation(UserTaggedObject) 234 220 235 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer. 221 236 invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer. 222 237 invalid_models.fielderrors: "charfield3": CharFields require a "max_length" attribute that is a positive integer. … … 324 339 invalid_models.nonexistingorderingwithsingleunderscore: "ordering" refers to "does_not_exist", a field that doesn't exist. 325 340 invalid_models.invalidsetnull: 'fk' specifies on_delete=SET_NULL, but cannot be null. 326 341 invalid_models.invalidsetdefault: 'fk' specifies on_delete=SET_DEFAULT, but has no default value. 342 invalid_models.articleattachment: model 'UserTaggedObject' must have a GenericForeignKey in order to create a GenericRelation. 327 343 """