Ticket #3055: ticket_30500.patch
File ticket_30500.patch, 2.9 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 26 27 27 28 e = ModelErrorCollection(outfile) 28 29 … … 225 226 "which has not been installed" % (f.name, f.rel.through) 226 227 ) 227 228 229 elif isinstance(f, GenericRelation): 230 if not any([isinstance(vfield, GenericForeignKey) for vfield in f.rel.to._meta.virtual_fields]): 231 e.add(opts, "model '%s' must have a GenericForeignKey in order to create a GenericRelation." % f.rel.to.__name__) 232 228 233 rel_opts = f.rel.to._meta 229 234 rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name() 230 235 rel_query_name = f.related_query_name() -
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 """