Ticket #11265: new_id_attribute_name_kwarg.patch
File new_id_attribute_name_kwarg.patch, 1004 bytes (added by , 15 years ago) |
---|
-
django/db/models/fields/related.py
660 660 class ForeignKey(RelatedField, Field): 661 661 empty_strings_allowed = False 662 662 def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs): 663 self.__id_attr_name = kwargs.pop('id_attr_name', None) 663 664 try: 664 665 to_name = to._meta.object_name.lower() 665 666 except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT … … 679 680 self.db_index = True 680 681 681 682 def get_attname(self): 682 return '%s_id' % self.name 683 if self.__id_attr_name: 684 return self.__id_attr_name 685 else: 686 return '%s_id' % self.name 683 687 684 688 def get_validator_unique_lookup_type(self): 685 689 return '%s__%s__exact' % (self.name, self.rel.get_related_field().name)