Today I'm going to tell you a story about how to add a custom filter to your Django Forms.
In the not too distance future, you'll be jamming to "White Snake" while you setup your own ninja searchable FAQ, you'll want your questions and answers to only show-up on your website. But right now we have a problem, I'm seeing other peoples domains because the Django ModelForm just pulls all websites in the Website table. Getmealplans.com is one of my wife's businesses but thepassionofvitamins.com belongs to my Jesus loving friend Jack. ¡No bueno!
I read and tried several solutions for customizing the view and form but nothing seemed to work. The most promising seemed to be to use
self.fields['website'].queryset = Website.objects.filter(organization__primary_account=self.request.user)
The tricky bitch of it was that the request object wasn't accessible via self or a directly passed parameter.
Because this shit works; well it works for 1 person yet at the same time is a giant security issue for that user.
self.fields['website'].queryset = Website.objects.filter(organization__primary_account=1)
So after much hand wringing and searching I couldn't find a solution that worked for me. I know I should be ashamed to call ...