Changes between Version 2 and Version 3 of ModelSyntaxChangeInstructions
- Timestamp:
- Aug 25, 2005, 3:06:40 PM (19 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ModelSyntaxChangeInstructions
v2 v3 1 = = Django model syntax change ==1 = Django model syntax change = 2 2 3 3 As of ____, Django's model syntax has changed. If you're using models that use old (pre-____) syntax, you'll need to convert them according to the these instructions. 4 4 5 == = What changed ===5 == What changed == 6 6 7 7 * Fields are now attributes of the model class, rather than members of a {{{fields}}} list. … … 11 11 * {{{rel_name}}} is no longer used for {{{ManyToManyField}}}s. If your model has more than one {{{ManyToManyField}}} to the same foreign model, differentiate the fields using the field name, not {{{rel_name}}}. Also, give both of the {{{ManyToManyField}}}s a {{{singular}}} attribute, which defines the name of the related object in singular format. (This is an obscure case, but it's included here for completeness.) 12 12 13 == = Examples ===13 == Examples == 14 14 15 Old syntax example: 15 === Old syntax example === 16 16 17 17 {{{ … … 19 19 class Foo(meta.Model): 20 20 fields = ( 21 meta.CharField('first_name', maxlength=30),21 meta.CharField('first_name', "The person's first name", maxlength=30), 22 22 meta.CharField('last_name', maxlength=30), 23 23 meta.ForeignKey(Bar), … … 32 32 }}} 33 33 34 New syntax example: 34 === New syntax example === 35 35 36 36 {{{ 37 37 #!python 38 38 class Foo(meta.Model): 39 first_name = meta.CharField( 'first_name', maxlength=30)40 last_name = meta.CharField( 'last_name',maxlength=30)39 first_name = meta.CharField("The person's first name", maxlength=30) 40 last_name = meta.CharField(maxlength=30) 41 41 bar = meta.ForeignKey(Bar) 42 42 sites = meta.ManyToManyField(Sites) … … 54 54 * {{{bar}}} and {{{sites}}} now have explicit names, and {{{admin.fields}}} was changed to use {{{bar}}} instead of {{{bar_id}}}. 55 55 * {{{ordering}}} was also changed to use the explicit name {{{bar}}} instead of {{{bar_id}}}. 56 * The {{{verbose_name}}} is now an optional first argument to {{{Field}}}s. For {{{ForeignKey}}}s, {{{ManyToManyField}}}s and {{{OneToOneField}}}s, use a named argument: {{{verbose_name="foo"}}}. 56 57 * Don't forget to remove the commas after each {{{Field}}}, because they're class attributes instead of list elements now.