Ticket #21940: #21940-virtual_only_in_contribute_to_class.diff
File #21940-virtual_only_in_contribute_to_class.diff, 4.1 KB (added by , 11 years ago) |
---|
-
django/db/models/fields/__init__.py
a b class AutoField(Field): 612 612 return None 613 613 return int(value) 614 614 615 def contribute_to_class(self, cls, name ):615 def contribute_to_class(self, cls, name, virtual_only=False): 616 616 assert not cls._meta.has_auto_field, \ 617 617 "A model can't have more than one AutoField." 618 super(AutoField, self).contribute_to_class(cls, name )618 super(AutoField, self).contribute_to_class(cls, name, virtual_only=virtual_only) 619 619 cls._meta.has_auto_field = True 620 620 cls._meta.auto_field = self 621 621 … … class DateField(Field): 777 777 else: 778 778 return super(DateField, self).pre_save(model_instance, add) 779 779 780 def contribute_to_class(self, cls, name ):781 super(DateField,self).contribute_to_class(cls, name )780 def contribute_to_class(self, cls, name, virtual_only=False): 781 super(DateField,self).contribute_to_class(cls, name, virtual_only=virtual_only) 782 782 if not self.null: 783 783 setattr(cls, 'get_next_by_%s' % self.name, 784 784 curry(cls._get_next_or_previous_by_FIELD, field=self, -
django/db/models/fields/files.py
a b class FileField(Field): 252 252 file.save(file.name, file, save=False) 253 253 return file 254 254 255 def contribute_to_class(self, cls, name ):256 super(FileField, self).contribute_to_class(cls, name )255 def contribute_to_class(self, cls, name, virtual_only=False): 256 super(FileField, self).contribute_to_class(cls, name, virtual_only=virtual_only) 257 257 setattr(cls, self.name, self.descriptor_class(self)) 258 258 259 259 def get_directory_name(self): … … class ImageField(FileField): 328 328 self.width_field, self.height_field = width_field, height_field 329 329 super(ImageField, self).__init__(verbose_name, name, **kwargs) 330 330 331 def contribute_to_class(self, cls, name ):332 super(ImageField, self).contribute_to_class(cls, name )331 def contribute_to_class(self, cls, name, virtual_only=False): 332 super(ImageField, self).contribute_to_class(cls, name, virtual_only=virtual_only) 333 333 # Attach update_dimension_fields so that dimension fields declared 334 334 # after their corresponding image field don't stay cleared by 335 335 # Model.__init__, see bug #11196. -
django/db/models/fields/related.py
a b class ManyToManyField(RelatedField): 1456 1500 data = [choices_list[0][0]] 1457 1501 return smart_text(data) 1458 1502 1459 def contribute_to_class(self, cls, name ):1503 def contribute_to_class(self, cls, name, virtual_only=False): 1460 1504 # To support multiple relations to self, it's useful to have a non-None 1461 1505 # related name on symmetrical relations for internal reasons. The 1462 1506 # concept doesn't make a lot of sense externally ("you want me to … … class ManyToManyField(RelatedField): 1466 1510 if self.rel.symmetrical and (self.rel.to == "self" or self.rel.to == cls._meta.object_name): 1467 1511 self.rel.related_name = "%s_rel_+" % name 1468 1512 1469 super(ManyToManyField, self).contribute_to_class(cls, name )1513 super(ManyToManyField, self).contribute_to_class(cls, name, virtual_only=virtual_only) 1470 1514 1471 1515 # The intermediate m2m model is not auto created if: 1472 1516 # 1) There is a manually specified intermediate, or -
django/db/models/fields/subclassing.py
a b def make_contrib(superclass, func=None): 43 43 case that the existing contribute_to_class() calls all the necessary 44 44 superclass methods. 45 45 """ 46 def contribute_to_class(self, cls, name ):46 def contribute_to_class(self, cls, name, virtual_only=False): 47 47 if func: 48 func(self, cls, name )48 func(self, cls, name, virtual_only=virtual_only) 49 49 else: 50 super(superclass, self).contribute_to_class(cls, name )50 super(superclass, self).contribute_to_class(cls, name, virtual_only=virtual_only) 51 51 setattr(cls, self.name, Creator(self)) 52 52 53 53 return contribute_to_class