Changes between Version 8 and Version 9 of CookBookCategoryDataModel
- Timestamp:
- Aug 21, 2005, 7:28:48 AM (19 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CookBookCategoryDataModel
v8 v9 13 13 fields = ( 14 14 meta.CharField('category_name', maxlength=50), 15 meta.CharField('category_parents', maxlength=250, editable=False), 16 meta.ForeignKey('self', blank=True, null=True, 15 meta.ForeignKey('self', blank=True, null=True, 17 16 rel_name='parent', related_name='child'), 17 meta.ForeignKey(User) 18 18 ) 19 unique_together = (("category_name", "category_parents"),)20 19 21 20 def _recurse_for_parents(self, cat_obj): … … 27 26 p_list.extend(more) 28 27 if cat_obj == self and p_list: 29 30 28 p_list.reverse() 31 29 return p_list … … 37 35 p_list = self._recurse_for_parents(self) 38 36 return self.get_separator().join(p_list) 37 _parents_repr.short_description = "Category parents" 39 38 40 39 def __repr__(self): 41 if self.category_parents: 42 l = [self.category_parents, self.category_name] 43 return self.get_separator().join(l) 44 return self.category_name 45 46 def _pre_save(self): 47 self.category_parents = self._parents_repr() 40 p_list = self._recurse_for_parents(self) 41 p_list.append(self.category_name) 42 return self.get_separator().join(p_list) 48 43 49 44 admin = meta.Admin( 50 list_display = ('category_name', ' category_parents'),51 search_fields = ['category_name' , 'category_parents'],45 list_display = ('category_name', '_parents_repr'), 46 search_fields = ['category_name'], 52 47 ) 53 ordering = ('category_parents', 'category_name')54 48 }}} 55 49 … … 119 113 http://www.djangoproject.com/documentation/models/m2o_recursive/ 120 114 121 == Comments ==122 123 This example has a bug: the field "category_parents" gets not updated, if a parent category was moved.124 125 E.g. you create the following categories:126 {{{127 firstcat128 secondcat129 secondcat :: thirdcat130 }}}131 132 133 Now you move "secondcat" under "firstcat". The correct display would be:134 {{{135 firstcat136 firstcat :: secondcat137 firstcat :: secondcat :: thirdcat138 }}}139 140 141 But because "category_parents" of thirdcat was not updated, you see:142 {{{143 firstcat144 firstcat :: secondcat145 secondcat :: thirdcat146 }}}147 148 149 In the database it is correct, just the display is incorrect.150 151 Can anybody fix this?