मैं इनलाइन मॉडल व्यवस्थापक से मूल उदाहरण कैसे प्राप्त कर सकता हूं?Django: इनलाइन मॉडल व्यवस्थापक से पेरेंट इंस्टेंस का उपयोग करें
मेरा लक्ष्य पेरेंट इंस्टेंस की स्थिति के आधार पर has_add_permission
फ़ंक्शन को ओवरराइड करना है। मैं एक बच्चे को जोड़ने के लिए अनुमति देने के लिए नहीं करना चाहते हैं माता-पिता की स्थिति अलग से 1.
class ChildInline(admin.TabularInline):
model = Child
form = ChildForm
fields = (
...
)
extra = 0
def has_add_permission(self, request):
# Return True only if the parent has status == 1
# How to get to the parent instance?
#return True
class ParentAdmin(admin.ModelAdmin):
inlines = [ChildInline,]
क्या आपने request.parent.status को देखा? – fiacre
'' WSGIRequest 'ऑब्जेक्ट में कोई विशेषता नहीं है' parent'' – Michael
क्या आपको कुछ समाधान मिला? –