2015-04-03 4 views
16

में मोंगोइंजिन के डायनेमिकएम्बेड डॉक्यूमेंट को संभालना मुझे एक समस्या है जिसके लिए मुझे मोंगोइंजिन के साथ फ्लास्क-एडमिन का उपयोग करके एक सरल समाधान नहीं मिल रहा है। मेरे पास ExerciseResourceContent नामक एक दस्तावेज़ श्रेणी है।फ्लास्क-एडमिन

class ExerciseQuestion(db.DynamicEmbeddedDocument): 
    """ 
    Generic collection, every question type will inherit from this. 
    Subclasses should override method "without_correct_answer" in order to define the version sent to clients. 
    Subclasses of questions depending on presentation parameters should also override method "with_computed_correct_answer". 
    """ 

    _id = db.ObjectIdField(default=ObjectId) 

    ## Question text 
    question_text = db.StringField(required=True) 

    ## Correct answer (field type depends on question type) 
    correct_answer = db.DynamicField() 

यह दो वर्गों में subclassed जा सकता है (और अधिक करने के लिए:

class ExerciseResourceContent(ResourceContent): 
    """An exercise with a list of questions.""" 

    ## Embedded list of questions 
    questions = db.ListField(db.EmbeddedDocumentField(ExerciseQuestion)) 

ExerciseQuestion दस्तावेज़ वास्तव में एक DynamicEmbeddedDocument है: यह एक "सवाल" विशेषता है, जो एक EmbeddedDocument के ListField बुलाया ExerciseQuestion है आ): MultipleAnswerMCQExerciseQuestion और UniqueAnswerMCQExerciseQuestion:

class MultipleAnswerMCQExerciseQuestion(ExerciseQuestion): 
    """Multiple choice question with several possible answers.""" 

    ## Propositions 
    propositions = db.ListField(db.EmbeddedDocumentField(MultipleAnswerMCQExerciseQuestionProposition)) 

    ## Correct answer 
    correct_answer = db.ListField(db.ObjectIdField()) 

class UniqueAnswerMCQExerciseQuestion(ExerciseQuestion): 
    """Multiple choice question with one possible answer only.""" 

    ## Propositions 
    propositions = db.ListField(db.EmbeddedDocumentField(UniqueAnswerMCQExerciseQuestionProposition)) 

    ## Correct answer 
    correct_answer = db.ObjectIdField() 

जब मैं ExerciseResourceContent बनाने या संपादित करने के लिए फ्लास्क-एडमिन का उपयोग करता हूं, तो यह एक "प्रश्न" सूची प्रदर्शित करता है, जिसमें से मैं "Question_text" विशेषता संपादित कर सकता हूं, लेकिन मुझे "Correct_Answer" विशेषता नहीं दिखाई दे सकती है, न ही कोई "प्रस्ताव" विशेषता जैसा मैं चाहता था मैंने फ्लास्क-एडमिन दस्तावेज़ से संघर्ष किया, लेकिन ऐसा लगता है कि यह गतिशील सामग्री (फ़ील्ड या दस्तावेज़) के साथ एक समस्या है, और दस्तावेज़ों में इसके बारे में कुछ भी नहीं है।

आपकी मदद के लिए धन्यवाद

उत्तर

0
import time 

sentence = "ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY" 
s = sentence.split() 
another = [0] 
time.sleep(0.5) 
print(sentence) 
    for count, i in enumerate(s): 
    if s.count(i) < 2: 
     another.append(max(another) + 1) 
    else: 
     another.append(s.index(i) +1) 
another.remove(0) 
time.sleep(0.5) 
print(another) 
file = open("N:\(Filedirectory)","w") 
file.write(another) 
file.write(s) 
+1

इस कोड को हो सकता है प्रश्न का उत्तर दें, इस कोड का उत्तर देने के तरीके के बारे में अतिरिक्त संदर्भ प्रदान करना और/या कैसे यह दीर्घकालिक मूल्य में सुधार करता है। –

1

मुझे ऐसा लगता है आप अपने मॉडल के लिए व्यवस्थापक-दृश्य को अनुकूलित करना है। यह एक ऐसा कार्य है जिसे आपको अपने मॉडल के लिए करना है यदि वे "बॉक्स से बाहर" सही तरीके से प्रदर्शित नहीं होते हैं।

ज्यादातर मामलों में आपको विचारों को पूरी तरह से लिखना नहीं है। ज्यादातर मामलों में अंतर्निहित विचारों को अनुकूलित करने के लिए पर्याप्त होगा।

मेरे पास फ्लास्क के लिए कोई अनुभव नहीं है, लेकिन आपको मूल रूप से ModelView उप-वर्ग करना होगा। और

#Customized admin views 
class ExerciseQuestionView(ModelView): 
# 
# add customisation code here 
# 

class MultipleAnswerMCQExerciseQuestionView(ModelView): 
# 
# add customisation code here 
# 

class UniqueAnswerMCQExerciseQuestionView(ModelView): 
# 
# add customisation code here 
# 

if __name__ == '__main__': 
    # Create admin 
    admin = admin.Admin(app, 'Example: MongoEngine') 

    # Add admin views 
    admin.add_view(ExerciseQuestionView(ExerciseQuestion)) 
    admin.add_view(MultipleAnswerMCQExerciseQuestionView(MultipleAnswerMCQExerciseQuestion)) 
    admin.add_view(UniqueAnswerMCQExerciseQuestionView(UniqueAnswerMCQExerciseQuestion)) 
    #... 

वैसे भी व्यवस्थापक के उपवर्ग रजिस्टर मुझे लगता है कि आप प्रलेखन के माध्यम से जाना चाहिए ... या आप बहुत लंबा यहाँ इंतजार कर खत्म हो सकता है ...

http://flask-admin.readthedocs.io/en/latest/api/mod_contrib_mongoengine/