Ticket #21940: #21940-virtual_only_in_contribute_to_class.diff

File #21940-virtual_only_in_contribute_to_class.diff, 4.1 KB (added by German M. Bravo, 11 years ago)
  • django/db/models/fields/__init__.py

    a b class AutoField(Field):  
    612612            return None
    613613        return int(value)
    614614
    615     def contribute_to_class(self, cls, name):
     615    def contribute_to_class(self, cls, name, virtual_only=False):
    616616        assert not cls._meta.has_auto_field, \
    617617               "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)
    619619        cls._meta.has_auto_field = True
    620620        cls._meta.auto_field = self
    621621
    class DateField(Field):  
    777777        else:
    778778            return super(DateField, self).pre_save(model_instance, add)
    779779
    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)
    782782        if not self.null:
    783783            setattr(cls, 'get_next_by_%s' % self.name,
    784784                curry(cls._get_next_or_previous_by_FIELD, field=self,
  • django/db/models/fields/files.py

    a b class FileField(Field):  
    252252            file.save(file.name, file, save=False)
    253253        return file
    254254
    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)
    257257        setattr(cls, self.name, self.descriptor_class(self))
    258258
    259259    def get_directory_name(self):
    class ImageField(FileField):  
    328328        self.width_field, self.height_field = width_field, height_field
    329329        super(ImageField, self).__init__(verbose_name, name, **kwargs)
    330330
    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)
    333333        # Attach update_dimension_fields so that dimension fields declared
    334334        # after their corresponding image field don't stay cleared by
    335335        # Model.__init__, see bug #11196.
  • django/db/models/fields/related.py

    a b class ManyToManyField(RelatedField):  
    14561500                    data = [choices_list[0][0]]
    14571501        return smart_text(data)
    14581502
    1459     def contribute_to_class(self, cls, name):
     1503    def contribute_to_class(self, cls, name, virtual_only=False):
    14601504        # To support multiple relations to self, it's useful to have a non-None
    14611505        # related name on symmetrical relations for internal reasons. The
    14621506        # concept doesn't make a lot of sense externally ("you want me to
    class ManyToManyField(RelatedField):  
    14661510        if self.rel.symmetrical and (self.rel.to == "self" or self.rel.to == cls._meta.object_name):
    14671511            self.rel.related_name = "%s_rel_+" % name
    14681512
    1469         super(ManyToManyField, self).contribute_to_class(cls, name)
     1513        super(ManyToManyField, self).contribute_to_class(cls, name, virtual_only=virtual_only)
    14701514
    14711515        # The intermediate m2m model is not auto created if:
    14721516        #  1) There is a manually specified intermediate, or
  • django/db/models/fields/subclassing.py

    a b def make_contrib(superclass, func=None):  
    4343    case that the existing contribute_to_class() calls all the necessary
    4444    superclass methods.
    4545    """
    46     def contribute_to_class(self, cls, name):
     46    def contribute_to_class(self, cls, name, virtual_only=False):
    4747        if func:
    48             func(self, cls, name)
     48            func(self, cls, name, virtual_only=virtual_only)
    4949        else:
    50             super(superclass, self).contribute_to_class(cls, name)
     50            super(superclass, self).contribute_to_class(cls, name, virtual_only=virtual_only)
    5151        setattr(cls, self.name, Creator(self))
    5252
    5353    return contribute_to_class
Back to Top