title: Django dynamic filterset
body: <p>So I want to create a <a href="https://django-filter.readthedocs.org/en/latest/ref/filters.html" rel="nofollow">django filters.FilterSet</a> from <a href="https://pypi.python.org/pypi/django-filter" rel="nofollow">django-filter module</a>, but I want to dynamically add its attributes. For example, if I wanted to add <code>SubName</code> dynamically:</p>
  
  <pre><code>class UsersInfoFilter(filters.FilterSet):
      Name=NumberFilter(lookup_type='gte')
      def __new__(self):
          self.SubName=NumberFilter(lookup_type='gte')
          self.Meta.fields.append('SubName')
      class Meta:
          model = UsersInfo
          fields = ['UserID', 'LanguageID', 'Name']
  </code></pre>
  
  <p>The problem is that FilterSet is a metaclass that immediately runs once the class has been figured out, so there is nowhere before that point that items can be dynamically added.</p>
  
  <p>I've tried putting a function in as a parameter around filters.FilterSet <code>class UsersInfo(AddObjects(filters.FilterSet))</code> which returns exactly what is passes, but I cannot reference <code>UsersInfoFilter</code> at that point since it still isn't finished being created.</p>
  
  <p>I also tried making <code>UsersInfoFilter</code> its own base class, and then creating a <code>class RealUsersInfoFilter(UsersInfoFilter, filters.FilterSet)</code> as my actual filter, but then FilterSet just throws warnings about missing attributes named as fields.</p>
  
  <p>There doesn't seem to be any kind of constructor function for classes in python. I'm assuming I have to do some kind of magic with metaclasses, but I've tried every combination I can think of and am at wits end.</p>