Ticket #15494: only_pk_related.diff

File only_pk_related.diff, 846 bytes (added by sym.roe@…, 14 years ago)
  • django/db/models/query.py

     
    708708            # Can only pass None to defer(), not only(), as the rest option.
    709709            # That won't stop people trying to do this, so let's be explicit.
    710710            raise TypeError("Cannot pass None as an argument to only().")
     711
     712        cleaned_fields = []
     713        for field_name in fields:
     714            if field_name == 'pk':
     715                field_name = self.model._meta.pk.name
     716            cleaned_fields.append(field_name)
     717
    711718        clone = self._clone()
    712         clone.query.add_immediate_loading(fields)
     719        clone.query.add_immediate_loading(cleaned_fields)
    713720        return clone
    714721
    715722    def using(self, alias):
Back to Top