Closed
Description
I'm wondering how to add type information for a Django project. For example, consider a typical Django model:
class Foo(models.Model):
field1 = models.TextField(choices=(('a', 'Choice A'), ('b', 'Choice B')))
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
The metaprogramming in Django will generate the following attributes and methods:
- Foo.objects, a QuerySet for Foo objects. For example Foo.objects.get(pk=1) will return a Foo object, and Foo.objects.filter(pk__gte=1) is an iterable of Foo objects.
- There will be an autogenerated method get_field1_display() for Foo. It returns the human readable value for foo field1's value (that is, it returns an str).
- foo.parent should be a Foo instance, foo.children should be a QuerySet of Foo instances.
The request itself for this issue is to document a way to add type information for meta-programming generated attributes and methods. Optimally this would be done as part of the meta-programming itself.