Ticket #2248: inline_models_in_Admin.diff
File inline_models_in_Admin.diff, 5.6 KB (added by , 18 years ago) |
---|
-
django/db/models/base.py
diff -ur --exclude-from=exc django_src/django/db/models/base.py django_src_new/django/db/models/base.py
17 17 import types 18 18 import sys 19 19 import os 20 try: 21 from threading import local 22 except ImportError: 23 from django.utils._threading_local import local 24 25 _thread_locals = local() 26 27 # This code is needed because we can't connect to the 28 # related inline_models' class prepared signals. 29 # At the time of class_prepared, the followed model 30 # isn't known to Python. So, we store the inline_models 31 # info in a variable inside threadlocals 32 _thread_locals.inline_models_info = {} 33 34 def inline_models_on_class_prepared(**kw_args): 35 sender = kw_args['sender'] 36 sender_fqn = "%s.%s" % (sender.__module__,sender.__name__) 37 if sender_fqn in _thread_locals.inline_models_info: 38 for inline_info in _thread_locals.inline_models_info[sender_fqn]: 39 parent_model = inline_info['parent_model'] 40 rel_fieldname = inline_info.get('related_field',None) 41 if rel_fieldname: 42 rel_field = sender._meta.get_field(rel_fieldname) 43 else: 44 fields = [x for x in sender._meta.fields if x.rel] 45 rel_field = [x for x in fields if x.rel.to==parent_model][0] 46 for key,val in inline_info.iteritems(): 47 if key=='type': 48 rel_field.rel.edit_inline = val 49 elif key=='fields': 50 for field in sender._meta.fields: 51 if field.name != rel_field.name: 52 field.core = field.name in val 53 elif hasattr(rel_field.rel,key): 54 setattr(rel_field.rel,key,val) 55 del _thread_locals.inline_models_info[sender_fqn] 56 57 dispatcher.connect(inline_models_on_class_prepared, 58 signal=signals.class_prepared) 59 # End of inline_models handling 20 60 21 61 class ModelBase(type): 22 62 "Metaclass for all models" … … 151 191 if hasattr(cls, 'get_absolute_url'): 152 192 cls.get_absolute_url = curry(get_absolute_url, opts, cls.get_absolute_url) 153 193 194 # Check the inline_models option 195 # and put the corresponding entry in the threadlocals var 196 # when needed 197 if cls._meta.admin: 198 for inline_info in cls._meta.admin.inline_models: 199 model_name = inline_info['model'] 200 if '.' not in model_name: 201 model_fqn = "%s.%s" % (cls.__module__,model_name) 202 else: 203 model_fqn = model_name 204 inline_info.update(parent_model=cls) 205 if _thread_locals.inline_models_info.get(model_fqn,None): 206 _thread_locals.inline_models_info[model_fqn].append(inline_info) 207 else: 208 _thread_locals.inline_models_info[model_fqn] = [inline_info] 209 154 210 dispatcher.send(signal=signals.class_prepared, sender=cls) 155 211 156 212 _prepare = classmethod(_prepare) -
django/db/models/options.py
diff -ur --exclude-from=exc django_src/django/db/models/options.py django_src_new/django/db/models/options.py
201 201 class AdminOptions(object): 202 202 def __init__(self, fields=None, js=None, list_display=None, list_filter=None, 203 203 date_hierarchy=None, save_as=False, ordering=None, search_fields=None, 204 save_on_top=False, list_select_related=False, manager=None, list_per_page=100): 204 save_on_top=False, list_select_related=False, manager=None, list_per_page=100, 205 inline_models=[]): 205 206 self.fields = fields 206 207 self.js = js or [] 207 208 self.list_display = list_display or ['__str__'] … … 212 213 self.save_on_top = save_on_top 213 214 self.list_select_related = list_select_related 214 215 self.list_per_page = list_per_page 216 self.inline_models = inline_models 215 217 self.manager = manager or Manager() 216 218 217 219 def get_field_sets(self, opts): -
django/docs/model-api.txt
diff -ru --exclude-from=exc django_src_new/docs/model-api.txt django_src/docs/model-api.txt
1176 1176 under the heading of the fieldset. It's used verbatim, so you can use any HTML 1177 1177 and you must escape any special HTML characters (such as ampersands) yourself. 1178 1178 1179 ``inline_models`` 1180 ----------------- 1181 A list of dicts that define which related models should be edited inline with 1182 the given model. It's a cleaner alternative to edit_inline, with the 1183 following differences: 1184 - You define the model with the 'model' keyword argument. You have to use 1185 the model as a ``string``, not the ``class``. 1186 - You can use the 'related_field' keyword to define the related model's 1187 ForeignKey that will be used, or leave Django to catch the first 1188 ForeignKey field to the parent model. 1189 - Instead of the 'edit_inline' keyword, you use the 'type' keyword. 1190 - Instead of specifying core=True in each field you want to show in 1191 the inline admin, you use the 'fields' keyword argument, which is 1192 a list of fields 1193 All other options can be used, e.g. ``min_num_in_admin``. 1194 1195 Example:: 1196 inline_models = ( 1197 {'model':'InlineModel', 1198 'type':models.TABULAR, 1199 'min_num_in_admin':1, 1200 'num_extra_on_change':1, 1201 'fields':('field1','field2','field3') 1202 }, 1203 ) 1204 1205 Check the ``edit_inline`` section for more arguments on this option. 1206 1179 1207 ``js`` 1180 1208 ------ 1181 1209