26 return formfield
27
28 def get_cache_key(self, db_field_name):
29 return u'_%s_%s_choices_cache' % (self.model._meta.db_table, db_field_name)
85 """
86 just save obj reference for future processing in Inline
87 """
88 request._obj_ = obj 89 return super(RecipeAdmin, self).get_form(request, obj, **kwargs)
90
91
62
63 if db_field.name == 'direction':
64 if request._obj_:
65 field.queryset = field.queryset.filter(recipe=request._obj_) 66 else:
67 field.queryset = field.queryset.none()
68
61 field = super(IngredientInlineAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
62
63 if db_field.name == 'direction':
64 if request._obj_: 65 field.queryset = field.queryset.filter(recipe=request._obj_)
66 else:
67 field.queryset = field.queryset.none()
Accessing a protected member (a member prefixed with _
) of a class from outside that class is not recommended, since the creator of that class did not intend this member to be exposed. If accesing this attribute outside of the class is absolutely needed, refactor it such that it becomes part of the public interface of the class.
class Rectangle(object):
def __init__(self, height, width):
self._height = height
self._width = width
r = Rectangle(4, 8)
area = r._height * r._width
class Rectangle(object):
def __init__(self, height, width):
self._height = height
self._width = width
def area():
return self._height * self._width
r = Rectangle(4, 8)
area = r.area()