Ticket #122: model_api.diff
File model_api.diff, 38.6 KB (added by , 19 years ago) |
---|
-
django/models/core.py
1 1 from django.core import meta, validators 2 2 3 3 class Site(meta.Model): 4 db_table = 'sites' 5 fields = ( 6 meta.CharField('domain', 'domain name', maxlength=100), 7 meta.CharField('name', 'display name', maxlength=50), 8 ) 9 ordering = ('domain',) 4 domain = meta.CharField('domain name', maxlength=100) 5 name = meta.CharField('display name', maxlength=50) 10 6 7 class Meta: 8 db_table = 'sites' 9 ordering = ('domain',) 10 11 11 def __repr__(self): 12 12 return self.domain 13 13 … … 17 17 return get_object(pk=SITE_ID) 18 18 19 19 class Package(meta.Model): 20 db_table = 'packages' 21 fields = ( 22 meta.CharField('label', 'label', maxlength=20, primary_key=True), 23 meta.CharField('name', 'name', maxlength=30, unique=True), 24 ) 25 ordering = ('name',) 20 label = meta.CharField(maxlength=20, primary_key=True) 21 name = meta.CharField(maxlength=30, unique=True) 26 22 23 class Meta: 24 db_table = 'packages' 25 ordering = ('name',) 26 27 27 def __repr__(self): 28 28 return self.name 29 29 30 30 class ContentType(meta.Model): 31 db_table = 'content_types' 32 fields = ( 33 meta.CharField('name', 'name', maxlength=100), 34 meta.ForeignKey(Package, name='package'), 35 meta.CharField('python_module_name', 'Python module name', maxlength=50), 36 ) 37 ordering = ('package', 'name') 38 unique_together = (('package', 'python_module_name'),) 31 name = meta.CharField(maxlength=100) 32 meta.ForeignKey(Package, name='package') 33 python_module_name = meta.CharField('Python module name', maxlength=50) 39 34 35 class Meta: 36 db_table = 'content_types' 37 ordering = ('package', 'name') 38 unique_together = (('package', 'python_module_name'),) 39 40 40 def __repr__(self): 41 41 return "%s | %s" % (self.package, self.name) 42 42 … … 54 54 return self.get_model_module().get_object(**kwargs) 55 55 56 56 class Redirect(meta.Model): 57 db_table = 'redirects' 58 fields = ( 59 meta.ForeignKey(Site, radio_admin=meta.VERTICAL), 60 meta.CharField('old_path', 'redirect from', maxlength=200, db_index=True, 61 help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'."), 62 meta.CharField('new_path', 'redirect to', maxlength=200, blank=True, 63 help_text="This can be either an absolute path (as above) or a full URL starting with 'http://'."), 64 ) 65 unique_together=(('site_id', 'old_path'),) 66 ordering = ('old_path',) 67 admin = meta.Admin( 68 list_display = ('__repr__',), 69 list_filter = ('site_id',), 70 search_fields = ('old_path', 'new_path'), 71 ) 57 meta.ForeignKey(Site, radio_admin=meta.VERTICAL) 58 old_path = meta.CharField('redirect from', maxlength=200, db_index=True, 59 help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'.") 60 new_path = meta.CharField('redirect to', maxlength=200, blank=True, 61 help_text="This can be either an absolute path (as above) or a full URL starting with 'http://'.") 72 62 63 class Meta: 64 db_table = 'redirects' 65 unique_together=(('site_id', 'old_path'),) 66 ordering = ('old_path',) 67 admin = meta.Admin( 68 list_display = ('__repr__',), 69 list_filter = ('site_id',), 70 search_fields = ('old_path', 'new_path'), 71 ) 72 73 73 def __repr__(self): 74 74 return "%s ---> %s" % (self.old_path, self.new_path) 75 75 76 76 class FlatFile(meta.Model): 77 db_table = 'flatfiles' 78 fields = ( 79 meta.CharField('url', 'URL', maxlength=100, validator_list=[validators.isAlphaNumericURL], 80 help_text="Example: '/about/contact/'. Make sure to have leading and trailing slashes."), 81 meta.CharField('title', 'title', maxlength=200), 82 meta.TextField('content', 'content', help_text="Full HTML is allowed."), 83 meta.BooleanField('enable_comments', 'enable comments'), 84 meta.CharField('template_name', 'template name', maxlength=70, blank=True, 85 help_text="Example: 'flatfiles/contact_page'. If this isn't provided, the system will use 'flatfiles/default'."), 86 meta.BooleanField('registration_required', 'registration required', 87 help_text="If this is checked, only logged-in users will be able to view the page."), 88 meta.ManyToManyField(Site), 89 ) 90 ordering = ('url',) 91 admin = meta.Admin( 92 fields = ( 93 (None, {'fields': ('url', 'title', 'content', 'sites')}), 94 ('Advanced options', {'classes': 'collapse', 'fields': ('enable_comments', 'registration_required', 'template_name')}), 95 ), 96 list_filter = ('sites',), 97 search_fields = ('url', 'title'), 98 ) 77 url = meta.CharField('URL', maxlength=100, validator_list=[validators.isAlphaNumericURL], 78 help_text="Example: '/about/contact/'. Make sure to have leading and trailing slashes.") 79 title = meta.CharField(maxlength=200) 80 content = meta.TextField(help_text="Full HTML is allowed.") 81 enable_comments = meta.BooleanField() 82 template_name = meta.CharField(maxlength=70, blank=True, 83 help_text="Example: 'flatfiles/contact_page'. If this isn't provided, the system will use 'flatfiles/default'.") 84 registration_required = meta.BooleanField(help_text="If this is checked, only logged-in users will be able to view the page.") 85 meta.ManyToManyField(Site) 99 86 87 class Meta: 88 db_table = 'flatfiles' 89 ordering = ('url',) 90 admin = meta.Admin( 91 fields = ( 92 (None, {'fields': ('url', 'title', 'content', 'sites')}), 93 ('Advanced options', {'classes': 'collapse', 'fields': ('enable_comments', 'registration_required', 'template_name')}), 94 ), 95 list_filter = ('sites',), 96 search_fields = ('url', 'title'), 97 ) 98 100 99 def __repr__(self): 101 100 return "%s -- %s" % (self.url, self.title) 102 101 -
django/models/auth.py
2 2 from django.models import core 3 3 4 4 class Permission(meta.Model): 5 fields = ( 6 meta.CharField('name', 'name', maxlength=50), 7 meta.ForeignKey(core.Package, name='package'), 8 meta.CharField('codename', 'code name', maxlength=100), 9 ) 10 unique_together = (('package', 'codename'),) 11 ordering = ('package', 'codename') 5 name = meta.CharField(maxlength=50) 6 meta.ForeignKey(core.Package, name='package') 7 codename = meta.CharField('code name', maxlength=100) 12 8 9 class Meta: 10 unique_together = (('package', 'codename'),) 11 ordering = ('package', 'codename') 12 13 13 def __repr__(self): 14 14 return "%s | %s" % (self.package, self.name) 15 15 16 16 class Group(meta.Model): 17 fields = ( 18 meta.CharField('name', 'name', maxlength=80, unique=True), 19 meta.ManyToManyField(Permission, blank=True, filter_interface=meta.HORIZONTAL), 20 ) 21 ordering = ('name',) 22 admin = meta.Admin( 23 search_fields = ('name',), 24 ) 17 name = meta.CharField(maxlength=80, unique=True) 18 meta.ManyToManyField(Permission, blank=True, filter_interface=meta.HORIZONTAL) 25 19 20 class Meta: 21 ordering = ('name',) 22 admin = meta.Admin( 23 search_fields = ('name',), 24 ) 25 26 26 def __repr__(self): 27 27 return self.name 28 28 29 29 class User(meta.Model): 30 fields = ( 31 meta.CharField('username', 'username', maxlength=30, unique=True, 32 validator_list=[validators.isAlphaNumeric]), 33 meta.CharField('first_name', 'first name', maxlength=30, blank=True), 34 meta.CharField('last_name', 'last name', maxlength=30, blank=True), 35 meta.EmailField('email', 'e-mail address', blank=True), 36 meta.CharField('password_md5', 'password', maxlength=32, help_text="Use an MD5 hash -- not the raw password."), 37 meta.BooleanField('is_staff', 'staff status', 38 help_text="Designates whether the user can log into this admin site."), 39 meta.BooleanField('is_active', 'active', default=True), 40 meta.BooleanField('is_superuser', 'superuser status'), 41 meta.DateTimeField('last_login', 'last login', default=meta.LazyDate()), 42 meta.DateTimeField('date_joined', 'date joined', default=meta.LazyDate()), 43 meta.ManyToManyField(Group, blank=True, 44 help_text="In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."), 45 meta.ManyToManyField(Permission, name='user_permissions', blank=True, filter_interface=meta.HORIZONTAL), 46 ) 47 ordering = ('username',) 48 exceptions = ('SiteProfileNotAvailable',) 49 admin = meta.Admin( 50 fields = ( 51 (None, {'fields': ('username', 'password_md5')}), 52 ('Personal info', {'fields': ('first_name', 'last_name', 'email')}), 53 ('Permissions', {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}), 54 ('Important dates', {'fields': ('last_login', 'date_joined')}), 55 ('Groups', {'fields': ('groups',)}), 56 ), 57 list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff'), 58 list_filter = ('is_staff', 'is_superuser'), 59 search_fields = ('username', 'first_name', 'last_name', 'email'), 60 ) 30 username = meta.CharField(maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric]) 31 first_name = meta.CharField(maxlength=30, blank=True) 32 last_name = meta.CharField(maxlength=30, blank=True) 33 email = meta.EmailField('e-mail address', blank=True) 34 password_md5 = meta.CharField('password', maxlength=32, help_text="Use an MD5 hash -- not the raw password.") 35 is_staff = meta.BooleanField('staff status', help_text="Designates whether the user can log into this admin site.") 36 is_active = meta.BooleanField('active', default=True) 37 is_superuser = meta.BooleanField('superuser status') 38 last_login = meta.DateTimeField(default=meta.LazyDate()) 39 date_joined = meta.DateTimeField(default=meta.LazyDate()) 40 meta.ManyToManyField(Group, blank=True, 41 help_text="In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.") 42 meta.ManyToManyField(Permission, name='user_permissions', blank=True, filter_interface=meta.HORIZONTAL) 61 43 44 class Meta: 45 ordering = ('username',) 46 exceptions = ('SiteProfileNotAvailable',) 47 admin = meta.Admin( 48 fields = ( 49 (None, {'fields': ('username', 'password_md5')}), 50 ('Personal info', {'fields': ('first_name', 'last_name', 'email')}), 51 ('Permissions', {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}), 52 ('Important dates', {'fields': ('last_login', 'date_joined')}), 53 ('Groups', {'fields': ('groups',)}), 54 ), 55 list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff'), 56 list_filter = ('is_staff', 'is_superuser'), 57 search_fields = ('username', 'first_name', 'last_name', 'email'), 58 ) 59 62 60 def __repr__(self): 63 61 return self.username 64 62 … … 173 171 return ''.join([choice(allowed_chars) for i in range(length)]) 174 172 175 173 class Session(meta.Model): 176 fields = ( 177 meta.ForeignKey(User), 178 meta.CharField('session_md5', 'session MD5 hash', maxlength=32), 179 meta.DateTimeField('start_time', 'start time', auto_now=True), 180 ) 181 module_constants = { 182 'TEST_COOKIE_NAME': 'testcookie', 183 'TEST_COOKIE_VALUE': 'worked', 184 } 174 meta.ForeignKey(User) 175 session_md5 = meta.CharField('session MD5 hash', maxlength=32) 176 start_time = meta.DateTimeField(auto_now=True) 185 177 178 class Meta: 179 module_constants = { 180 'TEST_COOKIE_NAME': 'testcookie', 181 'TEST_COOKIE_VALUE': 'worked', 182 } 183 186 184 def __repr__(self): 187 185 return "session started at %s" % self.start_time 188 186 … … 231 229 response.set_cookie(key, value, domain=cookie_domain) 232 230 233 231 class Message(meta.Model): 234 fields = ( 235 meta.AutoField('id', 'ID', primary_key=True), 236 meta.ForeignKey(User), 237 meta.TextField('message', 'message'), 238 ) 232 id = meta.AutoField('ID', primary_key=True) 233 meta.ForeignKey(User) 234 message = meta.TextField() 239 235 240 236 def __repr__(self): 241 237 return self.message 242 238 243 239 class LogEntry(meta.Model): 244 module_name = 'log' 245 verbose_name_plural = 'log entries' 246 db_table = 'auth_admin_log' 247 fields = ( 248 meta.DateTimeField('action_time', 'action time', auto_now=True), 249 meta.ForeignKey(User), 250 meta.ForeignKey(core.ContentType, name='content_type_id', rel_name='content_type', blank=True, null=True), 251 meta.IntegerField('object_id', 'object ID', blank=True, null=True), 252 meta.CharField('object_repr', 'object representation', maxlength=200), 253 meta.PositiveSmallIntegerField('action_flag', 'action flag'), 254 meta.TextField('change_message', 'change message', blank=True), 255 ) 256 ordering = ('-action_time',) 257 module_constants = { 258 'ADDITION': 1, 259 'CHANGE': 2, 260 'DELETION': 3, 261 } 240 action_time = meta.DateTimeField(auto_now=True) 241 meta.ForeignKey(User) 242 meta.ForeignKey(core.ContentType, name='content_type_id', rel_name='content_type', blank=True, null=True) 243 object_id = meta.IntegerField('object ID', blank=True, null=True) 244 object_repr = meta.CharField('object representation', maxlength=200) 245 action_flag = meta.PositiveSmallIntegerField() 246 change_message = meta.TextField(blank=True) 262 247 248 class Meta: 249 module_name = 'log' 250 verbose_name_plural = 'log entries' 251 db_table = 'auth_admin_log' 252 ordering = ('-action_time',) 253 module_constants = { 254 'ADDITION': 1, 255 'CHANGE': 2, 256 'DELETION': 3, 257 } 258 263 259 def __repr__(self): 264 260 return str(self.action_time) 265 261 -
django/core/meta/__init__.py
5 5 from django.core.meta.fields import * 6 6 from django.utils.functional import curry 7 7 from django.utils.text import capfirst 8 import copy, datetime, os, re, sys, types 8 import copy, datetime, os, re, sys, types, inspect 9 9 10 10 # Admin stages. 11 11 ADD, CHANGE, BOTH = 1, 2, 3 … … 196 196 for f in self.fields: 197 197 if f.primary_key: 198 198 self.pk = f 199 break 199 200 200 # If a primary_key field hasn't been specified, add an 201 201 # auto-incrementing primary-key ID field automatically. 202 202 if self.pk is None: 203 self.fields.insert(0, AutoField( 'id','ID', primary_key=True))203 self.fields.insert(0, AutoField(name='id', verbose_name='ID', primary_key=True)) 204 204 self.pk = self.fields[0] 205 205 206 206 def __repr__(self): … … 372 372 if not bases: 373 373 return type.__new__(cls, name, bases, attrs) 374 374 375 # Use the attributes from the imbedded class 'Meta', if it exists. 376 if attrs.has_key('Meta'): 377 meta_attrs = attrs['Meta'].__dict__ 378 del attrs['Meta'] 379 else: 380 meta_attrs = {} 381 382 # In order to make sure that we only add fields that were created inside of this 383 # class, we identify our model with a tuple containing the filename, and the class name. 384 model_ident = inspect.stack()[1][1], name 385 386 # Gather all of the attributes that are instances of Field. Apply the attribute name as needed. 387 fields = [] 388 for obj_name, obj in attrs.items(): 389 if isinstance(obj, Field): 390 if isinstance(obj,(ForeignKey, ManyToManyField, OneToOneField)): 391 obj.rel.name = obj_name 392 else: 393 obj.set_name(obj_name) 394 fields.append(obj) 395 del Field.instance_bank[model_ident][id(obj)] 396 del attrs[obj_name] 397 398 # Gather the fields that were not assigned to an attribute. 399 for obj_id, obj in Field.instance_bank[model_ident].items(): 400 fields.append(obj) 401 del Field.instance_bank[model_ident][obj_id] 402 403 # Sort the fields in the order that they were created. 404 fields.sort(lambda x,y: x.creation_counter - y.creation_counter) 405 375 406 # If this model is a subclass of another Model, create an Options 376 407 # object by first copying the base class's _meta and then updating it 377 408 # with the overrides from this class. 378 409 replaces_module = None 379 410 if bases[0] != Model: 380 if not attrs.has_key('fields'): 381 attrs['fields'] = list(bases[0]._meta._orig_init_args['fields'][:]) 382 if attrs.has_key('ignore_fields'): 383 ignore_fields = attrs.pop('ignore_fields') 411 # Inherent fields from the parent. In order to allow for overrides, we must make 412 # sure that we don't duplicate a name. 413 field_names = [f.name for f in fields] 414 for f in bases[0]._meta._orig_init_args['fields']: 415 if not f.name in field_names: 416 fields.append(f) 417 if meta_attrs.has_key('ignore_fields'): 418 ignore_fields = meta_attrs.pop('ignore_fields') 384 419 new_fields = [] 385 for i, f in enumerate(attrs['fields']):420 for f in fields: 386 421 if f.name not in ignore_fields: 387 422 new_fields.append(f) 388 attrs['fields'] = new_fields 389 if attrs.has_key('add_fields'): 390 attrs['fields'].extend(attrs.pop('add_fields')) 391 if attrs.has_key('replaces_module'): 423 fields = new_fields 424 if meta_attrs.has_key('replaces_module'): 392 425 # Set the replaces_module variable for now. We can't actually 393 426 # do anything with it yet, because the module hasn't yet been 394 427 # created. 395 replaces_module = attrs.pop('replaces_module').split('.')428 replaces_module = meta_attrs.pop('replaces_module').split('.') 396 429 # Pass any Options overrides to the base's Options instance, and 397 # simultaneously remove them from attrs. When this is done,attrs430 # simultaneously remove them from meta_attrs. When this is done, meta_attrs 398 431 # will be a dictionary of custom methods, plus __module__. 399 meta_overrides = { }400 for k, v in attrs.items():401 if not callable(v) andk != '__module__':402 meta_overrides[k] = attrs.pop(k)432 meta_overrides = {'fields':fields} 433 for k, v in meta_attrs.items(): 434 if k != '__module__': 435 meta_overrides[k] = meta_attrs.pop(k) 403 436 opts = bases[0]._meta.copy(**meta_overrides) 404 437 opts.object_name = name 405 438 del meta_overrides … … 408 441 # If the module_name wasn't given, use the class name 409 442 # in lowercase, plus a trailing "s" -- a poor-man's 410 443 # pluralization. 411 module_name = attrs.pop('module_name', name.lower() + 's'),444 module_name = meta_attrs.pop('module_name', name.lower() + 's'), 412 445 # If the verbose_name wasn't given, use the class name, 413 446 # converted from InitialCaps to "lowercase with spaces". 414 verbose_name = attrs.pop('verbose_name',447 verbose_name = meta_attrs.pop('verbose_name', 415 448 re.sub('([A-Z])', ' \\1', name).lower().strip()), 416 verbose_name_plural = attrs.pop('verbose_name_plural', ''),417 db_table = attrs.pop('db_table', ''),418 fields = attrs.pop('fields'),419 ordering = attrs.pop('ordering', None),420 unique_together = attrs.pop('unique_together', None),421 admin = attrs.pop('admin', None),422 has_related_links = attrs.pop('has_related_links', False),423 where_constraints = attrs.pop('where_constraints', None),449 verbose_name_plural = meta_attrs.pop('verbose_name_plural', ''), 450 db_table = meta_attrs.pop('db_table', ''), 451 fields = fields, 452 ordering = meta_attrs.pop('ordering', None), 453 unique_together = meta_attrs.pop('unique_together', None), 454 admin = meta_attrs.pop('admin', None), 455 has_related_links = meta_attrs.pop('has_related_links', False), 456 where_constraints = meta_attrs.pop('where_constraints', None), 424 457 object_name = name, 425 app_label = attrs.pop('app_label', None),426 exceptions = attrs.pop('exceptions', None),427 permissions = attrs.pop('permissions', None),428 get_latest_by = attrs.pop('get_latest_by', None),429 order_with_respect_to = attrs.pop('order_with_respect_to', None),430 module_constants = attrs.pop('module_constants', None),458 app_label = meta_attrs.pop('app_label', None), 459 exceptions = meta_attrs.pop('exceptions', None), 460 permissions = meta_attrs.pop('permissions', None), 461 get_latest_by = meta_attrs.pop('get_latest_by', None), 462 order_with_respect_to = meta_attrs.pop('order_with_respect_to', None), 463 module_constants = meta_attrs.pop('module_constants', None), 431 464 ) 432 465 433 466 # Dynamically create the module that will contain this class and its … … 450 483 for k, v in attrs.items(): 451 484 if k in ('__module__', '__init__', '_overrides', '__doc__'): 452 485 continue # Skip the important stuff. 486 # Make sure that this is a function, and give a helpful error otherwise. 487 if not callable(v): 488 raise ValueError("All attributes of a Model must be either a Field instance or a function. %s is a %s." % (k, type(v))) 453 489 # Give the function a function attribute "custom" to designate that 454 490 # it's a custom function/method. 455 491 v.custom = True -
django/core/meta/fields.py
3 3 from django.core.exceptions import ObjectDoesNotExist 4 4 from django.utils.functional import curry 5 5 from django.utils.text import capfirst 6 import datetime, os 6 import datetime, os, inspect 7 7 8 8 # Random entropy string used by "default" param. 9 9 NOT_PROVIDED = 'oijpwojefiojpanv' … … 46 46 47 47 class Field(object): 48 48 49 # Stores field instances. 50 instance_bank = {} 51 52 # Will be increased each time a Field object is instanced. Used to 53 # retain the order of fields. 54 creation_counter = 0 55 49 56 # Designates whether empty strings fundamentally are allowed at the 50 57 # database level. 51 58 empty_strings_allowed = True 52 59 53 def __init__(self, name, verbose_name=None,primary_key=False,60 def __init__(self, verbose_name=None, name=None, primary_key=False, 54 61 maxlength=None, unique=False, blank=False, null=False, db_index=None, 55 62 core=False, rel=None, default=NOT_PROVIDED, editable=True, 56 63 prepopulate_from=None, unique_for_date=None, unique_for_month=None, 57 64 unique_for_year=None, validator_list=None, choices=None, radio_admin=None, 58 65 help_text=''): 59 66 self.name = name 60 self.verbose_name = verbose_name or name .replace('_', ' ')67 self.verbose_name = verbose_name or name and name.replace('_', ' ') 61 68 self.primary_key = primary_key 62 69 self.maxlength, self.unique = maxlength, unique 63 70 self.blank, self.null = blank, null … … 82 89 else: 83 90 self.db_index = db_index 84 91 92 # Save the field instance, so that it can be retrieved later (in case it wasn't assigned to anything.) 93 # We will identify the class by a tuple containing the filename it was defined in, and it's own name. 94 # This is to make sure that a model only gets fields that were created inside of it's class. 95 stack = inspect.stack() 96 try: 97 # Walk up the stack until we find a name other than '__init__'. 98 while stack[0][3] == "__init__": 99 stack.pop(0) 100 model_ident = stack[0][1],stack[0][3] 101 finally: 102 del stack 103 if not Field.instance_bank.has_key(model_ident): 104 Field.instance_bank[model_ident] = {} 105 Field.instance_bank[model_ident][id(self)] = self 106 107 # Increase the creation counter, and save our local copy. 108 self.creation_counter = Field.creation_counter 109 Field.creation_counter += 1 110 111 def set_name(self, name): 112 """ 113 Sets the name, as well as the verbose_name if it is None. (Should be called when the 114 name is not availible at creation time.) 115 """ 116 self.name = name 117 self.verbose_name = self.verbose_name or self.name.replace('_',' ') 118 85 119 def pre_save(self, obj, value, add): 86 120 """ 87 121 Hook for altering the object obj based on the value of this field and … … 267 301 268 302 class DateField(Field): 269 303 empty_strings_allowed = False 270 def __init__(self, name, verbose_name=None, auto_now=False, auto_now_add=False, **kwargs):304 def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs): 271 305 self.auto_now, self.auto_now_add = auto_now, auto_now_add 272 306 if auto_now or auto_now_add: 273 307 kwargs['editable'] = False 274 Field.__init__(self, name, verbose_name, **kwargs)308 Field.__init__(self, verbose_name, name, **kwargs) 275 309 276 310 def get_db_prep_lookup(self, lookup_type, value): 277 311 if lookup_type == 'range': … … 323 357 return [formfields.EmailField] 324 358 325 359 class FileField(Field): 326 def __init__(self, name, verbose_name=None, upload_to='', **kwargs):360 def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs): 327 361 self.upload_to = upload_to 328 Field.__init__(self, name, verbose_name, **kwargs)362 Field.__init__(self, verbose_name, name, **kwargs) 329 363 330 364 def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False): 331 365 field_list = Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel) … … 388 422 389 423 class FloatField(Field): 390 424 empty_strings_allowed = False 391 def __init__(self, name, verbose_name=None, max_digits=None, decimal_places=None, **kwargs):425 def __init__(self, verbose_name=None, name=None, max_digits=None, decimal_places=None, **kwargs): 392 426 self.max_digits, self.decimal_places = max_digits, decimal_places 393 Field.__init__(self, name, verbose_name, **kwargs)427 Field.__init__(self, verbose_name, name, **kwargs) 394 428 395 429 def get_manipulator_field_objs(self): 396 430 return [curry(formfields.FloatField, max_digits=self.max_digits, decimal_places=self.decimal_places)] 397 431 398 432 class ImageField(FileField): 399 def __init__(self, name, verbose_name=None, width_field=None, height_field=None, **kwargs):433 def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs): 400 434 self.width_field, self.height_field = width_field, height_field 401 FileField.__init__(self, name, verbose_name, **kwargs)435 FileField.__init__(self, verbose_name, name, **kwargs) 402 436 403 437 def get_manipulator_field_objs(self): 404 438 return [formfields.ImageUploadField, formfields.HiddenField] … … 470 504 471 505 class TimeField(Field): 472 506 empty_strings_allowed = False 473 def __init__(self, name, verbose_name=None, auto_now=False, auto_now_add=False, **kwargs):507 def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs): 474 508 self.auto_now, self.auto_now_add = auto_now, auto_now_add 475 509 if auto_now or auto_now_add: 476 510 kwargs['editable'] = False 477 Field.__init__(self, name, verbose_name, **kwargs)511 Field.__init__(self, verbose_name, name, **kwargs) 478 512 479 513 def get_db_prep_lookup(self, lookup_type, value): 480 514 if lookup_type == 'range': … … 497 531 return [formfields.TimeField] 498 532 499 533 class URLField(Field): 500 def __init__(self, name, verbose_name=None, verify_exists=True, **kwargs):534 def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): 501 535 if verify_exists: 502 536 kwargs.setdefault('validator_list', []).append(validators.isExistingURL) 503 Field.__init__(self, name, verbose_name, **kwargs)537 Field.__init__(self, verbose_name, name, **kwargs) 504 538 505 539 def get_manipulator_field_objs(self): 506 540 return [formfields.URLField] … … 510 544 return [formfields.USStateField] 511 545 512 546 class XMLField(Field): 513 def __init__(self, name, verbose_name=None, schema_path=None, **kwargs):547 def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs): 514 548 self.schema_path = schema_path 515 Field.__init__(self, name, verbose_name, **kwargs)549 Field.__init__(self, verbose_name, name, **kwargs) 516 550 517 551 def get_manipulator_field_objs(self): 518 552 return [curry(formfields.XMLLargeTextField, schema_path=self.schema_path)] -
tests/testapp/models/repr.py
11 11 from django.core import meta 12 12 13 13 class Article(meta.Model): 14 fields = ( 15 meta.CharField('headline', maxlength=100), 16 meta.DateTimeField('pub_date'), 17 ) 14 headline = meta.CharField(maxlength=100) 15 pub_date = meta.DateTimeField() 18 16 19 17 def __repr__(self): 20 18 return self.headline -
tests/testapp/models/ordering.py
16 16 from django.core import meta 17 17 18 18 class Article(meta.Model): 19 fields = ( 20 meta.CharField('headline', maxlength=100), 21 meta.DateTimeField('pub_date'), 22 ) 23 ordering = ('-pub_date', 'headline') 19 headline = meta.CharField(maxlength=100) 20 pub_date = meta.DateTimeField() 24 21 22 class Meta: 23 ordering = ('-pub_date', 'headline') 24 25 25 def __repr__(self): 26 26 return self.headline 27 27 -
tests/testapp/models/lookup.py
7 7 from django.core import meta 8 8 9 9 class Article(meta.Model): 10 fields = ( 11 meta.CharField('headline', maxlength=100), 12 meta.DateTimeField('pub_date'), 13 ) 14 ordering = ('-pub_date', 'headline') 10 headline = meta.CharField(maxlength=100) 11 pub_date = meta.DateTimeField() 15 12 13 class Meta: 14 ordering = ('-pub_date', 'headline') 15 16 16 def __repr__(self): 17 17 return self.headline 18 18 -
tests/testapp/models/many_to_many.py
10 10 from django.core import meta 11 11 12 12 class Publication(meta.Model): 13 fields = ( 14 meta.CharField('title', maxlength=30), 15 ) 13 title = meta.CharField(maxlength=30) 16 14 17 15 def __repr__(self): 18 16 return self.title 19 17 20 18 class Article(meta.Model): 21 fields = ( 22 meta.CharField('headline', maxlength=100), 23 meta.ManyToManyField(Publication), 24 ) 19 headline = meta.CharField(maxlength=100) 20 meta.ManyToManyField(Publication) 25 21 26 22 def __repr__(self): 27 23 return self.headline -
tests/testapp/models/get_latest.py
11 11 from django.core import meta 12 12 13 13 class Article(meta.Model): 14 fields = ( 15 meta.CharField('headline', maxlength=100), 16 meta.DateTimeField('pub_date'), 17 ) 18 get_latest_by = 'pub_date' 14 headline = meta.CharField(maxlength=100) 15 pub_date = meta.DateTimeField() 19 16 17 class Meta: 18 get_latest_by = 'pub_date' 19 20 20 def __repr__(self): 21 21 return self.headline 22 22 -
tests/testapp/models/custom_methods.py
23 23 from django.core import meta 24 24 25 25 class Article(meta.Model): 26 fields = ( 27 meta.CharField('headline', maxlength=100), 28 meta.DateField('pub_date'), 29 ) 26 headline = meta.CharField(maxlength=100) 27 pub_date = meta.DateField() 30 28 31 29 def __repr__(self): 32 30 return self.headline -
tests/testapp/models/basic.py
7 7 from django.core import meta 8 8 9 9 class Article(meta.Model): 10 fields = ( 11 meta.CharField('headline', maxlength=100, default='Default headline'), 12 meta.DateTimeField('pub_date'), 13 ) 10 headline = meta.CharField(maxlength=100, default='Default headline') 11 pub_date = meta.DateTimeField() 14 12 13 15 14 API_TESTS = """ 16 15 # No articles are in the system yet. 17 16 >>> articles.get_list() -
tests/testapp/models/m2o_recursive.py
15 15 from django.core import meta 16 16 17 17 class Category(meta.Model): 18 module_name = 'categories' 19 fields = ( 20 meta.CharField('name', maxlength=20), 21 meta.ForeignKey('self', null=True, 22 rel_name='parent', related_name='child'), 23 ) 18 name = meta.CharField(maxlength=20) 19 parent = meta.ForeignKey('self', null=True, related_name='child') 20 21 class Meta: 22 module_name = 'categories' 24 23 25 24 def __repr__(self): 26 25 return self.name -
tests/testapp/models/one_to_one.py
9 9 from django.core import meta 10 10 11 11 class Place(meta.Model): 12 fields = ( 13 meta.CharField('name', maxlength=50), 14 meta.CharField('address', maxlength=80), 15 ) 12 name = meta.CharField(maxlength=50) 13 address = meta.CharField(maxlength=80) 16 14 17 15 def __repr__(self): 18 16 return "%s the place" % self.name 19 17 20 18 class Restaurant(meta.Model): 21 fields = ( 22 meta.OneToOneField(Place), 23 meta.BooleanField('serves_hot_dogs'), 24 meta.BooleanField('serves_pizza'), 25 ) 19 meta.OneToOneField(Place) 20 serves_hot_dogs = meta.BooleanField() 21 serves_pizza = meta.BooleanField() 26 22 27 23 def __repr__(self): 28 24 return "%s the restaurant" % self.get_place().name -
tests/testapp/models/m2o_recursive2.py
14 14 from django.core import meta 15 15 16 16 class Person(meta.Model): 17 fields = ( 18 meta.CharField('full_name', maxlength=20), 19 meta.ForeignKey('self', null=True, rel_name='mother', 20 related_name='mothers_child'), 21 meta.ForeignKey('self', null=True, rel_name='father', 22 related_name='fathers_child'), 23 ) 17 full_name = meta.CharField(maxlength=20) 18 mother = meta.ForeignKey('self', null=True, related_name='mothers_child') 19 father = meta.ForeignKey('self', null=True, related_name='fathers_child') 24 20 25 21 def __repr__(self): 26 22 return self.full_name -
tests/testapp/models/many_to_one.py
7 7 from django.core import meta 8 8 9 9 class Reporter(meta.Model): 10 fields = ( 11 meta.CharField('first_name', maxlength=30), 12 meta.CharField('last_name', maxlength=30), 13 ) 10 first_name = meta.CharField(maxlength=30) 11 last_name = meta.CharField(maxlength=30) 14 12 15 13 def __repr__(self): 16 14 return "%s %s" % (self.first_name, self.last_name) 17 15 18 16 class Article(meta.Model): 19 fields = ( 20 meta.CharField('headline', maxlength=100), 21 meta.DateField('pub_date'), 22 meta.ForeignKey(Reporter), 23 ) 17 headline = meta.CharField(maxlength=100) 18 pub_date = meta.DateField() 19 meta.ForeignKey(Reporter) 24 20 25 21 def __repr__(self): 26 22 return self.headline -
tests/testapp/models/m2m_intermediary.py
13 13 from django.core import meta 14 14 15 15 class Reporter(meta.Model): 16 fields = ( 17 meta.CharField('first_name', maxlength=30), 18 meta.CharField('last_name', maxlength=30), 19 ) 16 first_name = meta.CharField(maxlength=30) 17 last_name = meta.CharField(maxlength=30) 20 18 21 19 def __repr__(self): 22 20 return "%s %s" % (self.first_name, self.last_name) 23 21 24 22 class Article(meta.Model): 25 fields = ( 26 meta.CharField('headline', maxlength=100), 27 meta.DateField('pub_date'), 28 ) 23 headline = meta.CharField(maxlength=100) 24 pub_date = meta.DateField() 29 25 30 26 def __repr__(self): 31 27 return self.headline 32 28 33 29 class Writer(meta.Model): 34 fields = ( 35 meta.ForeignKey(Reporter), 36 meta.ForeignKey(Article), 37 meta.CharField('position', maxlength=100), 38 ) 30 meta.ForeignKey(Reporter) 31 meta.ForeignKey(Article) 32 position = meta.CharField(maxlength=100) 39 33 40 34 def __repr__(self): 41 35 return '%r (%s)' % (self.get_reporter(), self.position)