diff options
| author | Karen Tracey <kmtracey@gmail.com> | 2009-12-12 20:36:31 +0000 |
|---|---|---|
| committer | Karen Tracey <kmtracey@gmail.com> | 2009-12-12 20:36:31 +0000 |
| commit | fa591297533b4949a2414fbb27a9ff4b48ea482c (patch) | |
| tree | 9ec984069b89e198871e353cb2a6d84f81f231c1 /django/db | |
| parent | 7f1c309cac93b63a4f2c9620802a60a7dc065f66 (diff) | |
[1.1.X] Fixed #7977: Fixed admindocs to use docstrings instead of a static array to locate type information. Thanks J. Clifford Dyer.
r11833 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11834 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/fields/__init__.py | 52 | ||||
| -rw-r--r-- | django/db/models/fields/files.py | 4 | ||||
| -rw-r--r-- | django/db/models/fields/related.py | 11 |
3 files changed, 64 insertions, 3 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index a3007a7f66..05238cf797 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -49,6 +49,8 @@ class FieldDoesNotExist(Exception): # getattr(obj, opts.pk.attname) class Field(object): + """Base class for all field types""" + # Designates whether empty strings fundamentally are allowed at the # database level. empty_strings_allowed = True @@ -340,7 +342,10 @@ class Field(object): return getattr(obj, self.attname) class AutoField(Field): + """Integer""" + empty_strings_allowed = False + def __init__(self, *args, **kwargs): assert kwargs.get('primary_key', False) is True, "%ss must have primary_key=True." % self.__class__.__name__ kwargs['blank'] = True @@ -370,7 +375,10 @@ class AutoField(Field): return None class BooleanField(Field): + """Boolean (Either True or False)""" + empty_strings_allowed = False + def __init__(self, *args, **kwargs): kwargs['blank'] = True if 'default' not in kwargs and not kwargs.get('null'): @@ -413,6 +421,8 @@ class BooleanField(Field): return super(BooleanField, self).formfield(**defaults) class CharField(Field): + """String (up to %(max_length)s)""" + def get_internal_type(self): return "CharField" @@ -434,6 +444,8 @@ class CharField(Field): # TODO: Maybe move this into contrib, because it's specialized. class CommaSeparatedIntegerField(CharField): + """Comma-separated integers""" + def formfield(self, **kwargs): defaults = { 'form_class': forms.RegexField, @@ -449,7 +461,10 @@ class CommaSeparatedIntegerField(CharField): ansi_date_re = re.compile(r'^\d{4}-\d{1,2}-\d{1,2}$') class DateField(Field): + """Date (without time)""" + empty_strings_allowed = False + def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs): self.auto_now, self.auto_now_add = auto_now, auto_now_add #HACKs : auto_now_add/auto_now should be done as a default or a pre_save. @@ -524,6 +539,8 @@ class DateField(Field): return super(DateField, self).formfield(**defaults) class DateTimeField(DateField): + """Date (with time)""" + def get_internal_type(self): return "DateTimeField" @@ -583,7 +600,10 @@ class DateTimeField(DateField): return super(DateTimeField, self).formfield(**defaults) class DecimalField(Field): + """Decimal number""" + empty_strings_allowed = False + def __init__(self, verbose_name=None, name=None, max_digits=None, decimal_places=None, **kwargs): self.max_digits, self.decimal_places = max_digits, decimal_places Field.__init__(self, verbose_name, name, **kwargs) @@ -637,6 +657,8 @@ class DecimalField(Field): return super(DecimalField, self).formfield(**defaults) class EmailField(CharField): + """E-mail address""" + def __init__(self, *args, **kwargs): kwargs['max_length'] = kwargs.get('max_length', 75) CharField.__init__(self, *args, **kwargs) @@ -647,6 +669,8 @@ class EmailField(CharField): return super(EmailField, self).formfield(**defaults) class FilePathField(Field): + """File path""" + def __init__(self, verbose_name=None, name=None, path='', match=None, recursive=False, **kwargs): self.path, self.match, self.recursive = path, match, recursive kwargs['max_length'] = kwargs.get('max_length', 100) @@ -666,6 +690,8 @@ class FilePathField(Field): return "FilePathField" class FloatField(Field): + """Floating point number""" + empty_strings_allowed = False def get_db_prep_value(self, value): @@ -691,7 +717,10 @@ class FloatField(Field): return super(FloatField, self).formfield(**defaults) class IntegerField(Field): + """Integer""" + empty_strings_allowed = False + def get_db_prep_value(self, value): if value is None: return None @@ -715,7 +744,10 @@ class IntegerField(Field): return super(IntegerField, self).formfield(**defaults) class IPAddressField(Field): + """IP address""" + empty_strings_allowed = False + def __init__(self, *args, **kwargs): kwargs['max_length'] = 15 Field.__init__(self, *args, **kwargs) @@ -729,7 +761,10 @@ class IPAddressField(Field): return super(IPAddressField, self).formfield(**defaults) class NullBooleanField(Field): + """Boolean (Either True, False or None)""" + empty_strings_allowed = False + def __init__(self, *args, **kwargs): kwargs['null'] = True Field.__init__(self, *args, **kwargs) @@ -769,6 +804,8 @@ class NullBooleanField(Field): return super(NullBooleanField, self).formfield(**defaults) class PositiveIntegerField(IntegerField): + """Integer""" + def get_internal_type(self): return "PositiveIntegerField" @@ -778,6 +815,8 @@ class PositiveIntegerField(IntegerField): return super(PositiveIntegerField, self).formfield(**defaults) class PositiveSmallIntegerField(IntegerField): + """Integer""" + def get_internal_type(self): return "PositiveSmallIntegerField" @@ -787,6 +826,8 @@ class PositiveSmallIntegerField(IntegerField): return super(PositiveSmallIntegerField, self).formfield(**defaults) class SlugField(CharField): + """String (up to %(max_length)s)""" + def __init__(self, *args, **kwargs): kwargs['max_length'] = kwargs.get('max_length', 50) # Set db_index=True unless it's been set manually. @@ -803,10 +844,14 @@ class SlugField(CharField): return super(SlugField, self).formfield(**defaults) class SmallIntegerField(IntegerField): + """Integer""" + def get_internal_type(self): return "SmallIntegerField" class TextField(Field): + """Text""" + def get_internal_type(self): return "TextField" @@ -816,7 +861,10 @@ class TextField(Field): return super(TextField, self).formfield(**defaults) class TimeField(Field): + """Time""" + empty_strings_allowed = False + def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs): self.auto_now, self.auto_now_add = auto_now, auto_now_add if auto_now or auto_now_add: @@ -888,6 +936,8 @@ class TimeField(Field): return super(TimeField, self).formfield(**defaults) class URLField(CharField): + """URL""" + def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): kwargs['max_length'] = kwargs.get('max_length', 200) self.verify_exists = verify_exists @@ -899,6 +949,8 @@ class URLField(CharField): return super(URLField, self).formfield(**defaults) class XMLField(TextField): + """XML text""" + def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs): self.schema_path = schema_path Field.__init__(self, verbose_name, name, **kwargs) diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index aab4f3789f..7689d64dcf 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -209,6 +209,8 @@ class FileDescriptor(object): instance.__dict__[self.field.name] = value class FileField(Field): + """File path""" + # The class to wrap instance attributes in. Accessing the file object off # the instance will always return an instance of attr_class. attr_class = FieldFile @@ -323,6 +325,8 @@ class ImageFieldFile(ImageFile, FieldFile): super(ImageFieldFile, self).delete(save) class ImageField(FileField): + """File path""" + attr_class = ImageFieldFile descriptor_class = ImageFileDescriptor diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 529898ea27..95a4a4e6e3 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -682,6 +682,8 @@ class ManyToManyRel(object): return self.to._meta.pk class ForeignKey(RelatedField, Field): + """Foreign Key (type determined by related field)""" + empty_strings_allowed = False def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs): try: @@ -771,12 +773,13 @@ class ForeignKey(RelatedField, Field): return rel_field.db_type() class OneToOneField(ForeignKey): - """ + """One-to-one relationship + A OneToOneField is essentially the same as a ForeignKey, with the exception that always carries a "unique" constraint with it and the reverse relation always returns the object pointed to (since there will only ever be one), - rather than returning a list. - """ + rather than returning a list.""" + def __init__(self, to, to_field=None, **kwargs): kwargs['unique'] = True super(OneToOneField, self).__init__(to, to_field, OneToOneRel, **kwargs) @@ -791,6 +794,8 @@ class OneToOneField(ForeignKey): return super(OneToOneField, self).formfield(**kwargs) class ManyToManyField(RelatedField, Field): + """Many-to-many relationship""" + def __init__(self, to, **kwargs): try: assert not to._meta.abstract, "%s cannot define a relation with abstract class %s" % (self.__class__.__name__, to._meta.object_name) |
