{"action":"closed","issue":{"url":"https://api.github.com/repos/funkybob/django-sniplates/issues/33","labels_url":"https://api.github.com/repos/funkybob/django-sniplates/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/funkybob/django-sniplates/issues/33/comments","events_url":"https://api.github.com/repos/funkybob/django-sniplates/issues/33/events","html_url":"https://github.com/funkybob/django-sniplates/issues/33","id":107462156,"number":33,"title":"Possible to get rid of `display`?","user":{"login":"sergei-maertens","id":5518550,"avatar_url":"https://avatars.githubusercontent.com/u/5518550?v=3","gravatar_id":"","url":"https://api.github.com/users/sergei-maertens","html_url":"https://github.com/sergei-maertens","followers_url":"https://api.github.com/users/sergei-maertens/followers","following_url":"https://api.github.com/users/sergei-maertens/following{/other_user}","gists_url":"https://api.github.com/users/sergei-maertens/gists{/gist_id}","starred_url":"https://api.github.com/users/sergei-maertens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergei-maertens/subscriptions","organizations_url":"https://api.github.com/users/sergei-maertens/orgs","repos_url":"https://api.github.com/users/sergei-maertens/repos","events_url":"https://api.github.com/users/sergei-maertens/events{/privacy}","received_events_url":"https://api.github.com/users/sergei-maertens/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-09-21T08:03:27Z","updated_at":"2015-09-22T08:21:15Z","closed_at":"2015-09-22T08:21:15Z","body":"I have this use case: an inline_formset with a ModelForm, these are the models involved:\r\n\r\n    class Build(models.Model):\r\n        title = models.CharField(max_length=50)\r\n\r\n    class BuildPhoto(models.Model):\r\n        build = models.ForeignKey(Build)\r\n        photo = models.ForeignKey('albums.Photo')\r\n        url = models.URLField(blank=True)\r\n\r\n        def __unicode__(self):\r\n            return self.build.title  # simplified, but traverses the FK\r\n\r\n\r\n    class BuildPhotoForm(forms.ModelForm):\r\n        class Meta:\r\n            model = BuildPhoto\r\n            widgets = {'photo': forms.HiddenInput}\r\n\r\n\r\nNow, when I make an inlineformset for BuildPhotoForm with BuildPhoto, Django adds the 'id' field in BuildPhotoForm (django.forms.models.BaseModelFormSet.add_fields). This field is a ModelChoiceField and the queryset is not configurable, except if you subclass the BaseFormSet and override add_fields to modify this.\r\n\r\nThis is a HiddenInput widget by default, just like the 'photo' field. However, for these widgets in sniplates, the 'choices' is evaluated, while for ModelChoiceFields `field.choices` is a ModelChoiceIterator and thus lazy. This is very costly for the `id` field in my case, as it traverses the FK, leading to a query bomb in my template. I have no interest in the `choices`. It seems to me that `choices` is only evaluated to get the `display` of the field, so I vote for getting rid of `display`. It doesn't make a lot of sense in multiple-value fields anyway. Or, if it's needed, make it lazy.\r\n\r\nConcrete example: I was getting +3000 queries before subclassing, after 'fixing' it in my subclassed BaseFormSet, I'm only getting 27 queries.\r\n\r\nThoughts?"}}