Index: django/contrib/admin/options.py
===================================================================
--- django/contrib/admin/options.py	(revision 8151)
+++ django/contrib/admin/options.py	(working copy)
@@ -122,7 +122,7 @@
     radio_fields = {}
     prepopulated_fields = {}
 
-    def formfield_for_dbfield(self, db_field, **kwargs):
+    def formfield_for_dbfield(self, db_field, request, **kwargs):
         """
         Hook for specifying the form Field instance for a given database Field
         instance.
@@ -152,31 +152,37 @@
 
         # For ForeignKey or ManyToManyFields, use a special widget.
         if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
+            if hasattr(self, 'dynamic_%s_choices' % db_field.name):
+                formfield = db_field.formfield(queryset = getattr(self, 'dynamic_%s_choices' % db_field.name)(request, db_field.rel.to), **kwargs)
+            else:
+                formfield = db_field.formfield(**kwargs) 
             if isinstance(db_field, models.ForeignKey) and db_field.name in self.raw_id_fields:
-                kwargs['widget'] = widgets.ForeignKeyRawIdWidget(db_field.rel)
+                formfield.widget = widgets.ForeignKeyRawIdWidget(db_field.rel)
             elif isinstance(db_field, models.ForeignKey) and db_field.name in self.radio_fields:
-                kwargs['widget'] = widgets.AdminRadioSelect(attrs={
+                formfield.widget = widgets.AdminRadioSelect(attrs={
                     'class': get_ul_class(self.radio_fields[db_field.name]),
                 })
-                kwargs['empty_label'] = db_field.blank and _('None') or None
+                formfield.empty_label = db_field.blank and _('None') or None
             else:
                 if isinstance(db_field, models.ManyToManyField):
                     # If it uses an intermediary model, don't show field in admin. 
                     if db_field.rel.through is not None:
                         return None
                     elif db_field.name in self.raw_id_fields:
-                        kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.rel)
-                        kwargs['help_text'] = ''
+                        formfield.widget = widgets.ManyToManyRawIdWidget(db_field.rel)
+                        formfield.help_text = ''
                     elif db_field.name in (list(self.filter_vertical) + list(self.filter_horizontal)):
-                        kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name, (db_field.name in self.filter_vertical))
+                        formfield.widget = widgets.FilteredSelectMultiple(db_field.verbose_name, (db_field.name in self.filter_vertical))
             # Wrap the widget's render() method with a method that adds
             # extra HTML to the end of the rendered output.
-            formfield = db_field.formfield(**kwargs)
             # Don't wrap raw_id fields. Their add function is in the popup window.
             if not db_field.name in self.raw_id_fields:
                 formfield.widget = widgets.RelatedFieldWidgetWrapper(formfield.widget, db_field.rel, self.admin_site)
             return formfield
-        
+ 
+        if isinstance(db_field, (models.OneToOneField)) and hasattr(self, 'dynamic_%s_choices' % db_field.name):
+            return db_field.formfield(queryset = getattr(self, 'dynamic_%s_choices' % db_field.name)(request, db_field.rel.to), **kwargs)
+           
         if db_field.choices and db_field.name in self.radio_fields:
             kwargs['widget'] = widgets.AdminRadioSelect(
                 choices=db_field.get_choices(include_blank=db_field.blank,
@@ -322,7 +328,7 @@
             fields = flatten_fieldsets(self.declared_fieldsets)
         else:
             fields = None
-        return modelform_factory(self.model, form=self.form, fields=fields, formfield_callback=self.formfield_for_dbfield)
+        return modelform_factory(self.model, form=self.form, fields=fields, formfield_callback=lambda f, **kwargs: self.formfield_for_dbfield(f, request, **kwargs))
 
     def get_formsets(self, request, obj=None):
         for inline in self.inline_instances:
@@ -728,7 +734,7 @@
             fields = None
         return inlineformset_factory(self.parent_model, self.model,
             form=self.form, formset=self.formset, fk_name=self.fk_name,
-            fields=fields, formfield_callback=self.formfield_for_dbfield,
+            fields=fields, formfield_callback=lambda f, **kwargs: self.formfield_for_dbfield(f, request, **kwargs),
             extra=self.extra, max_num=self.max_num)
 
     def get_fieldsets(self, request, obj=None):
