1

私は私のモデル(相談及びアセスメント)内のエンティティの2種類があります:作成したデータストアに入れてご相談ください。まずAppEngineの - 使用して一から一関係で別のオブジェクトを結合する方法キー

class Consults(ndb.Model): 

# Basic Consult Info (To get started storing a consult in the datastore) 

    # Timestamp consult submitted to datastore 
    consult_created = ndb.DateTimeProperty(auto_now_add=True) 
    # Consult booking date 
    consult_date = ndb.StringProperty() 
    # Consult booking time 
    consult_time = ndb.StringProperty() 
    # Provider booking the consult 
    consult_user = ndb.StringProperty() 
    # Consult status: (Pending, Completed, Cancelled) 
    consult_status = ndb.StringProperty(choices=('Pending','Completed','Cancelled'),default='Pending') 

# Patient Info 

    # The patient's first name 
    patient_first = ndb.StringProperty() 
    # The patient's last name 
    patient_last = ndb.StringProperty() 
    # The patient's email address 
    patient_phone = ndb.StringProperty() 
    # The patient's phone number 
    patient_email = ndb.StringProperty() 
    # The patient's age in years 
    patient_age = ndb.IntegerProperty() 
    # Does the patient agree to emails from JW? 
    patient_optin = ndb.BooleanProperty() 

# Clinical Info 

    # Does the patient use an orthodic? 
    clin_ortho = ndb.BooleanProperty() 
    # Foot type:(Over Pronated, Moderatly Pronated, Neturtal, Supinated, Orthosis) 
    clin_type = ndb.StringProperty(choices=('Over Pronated','Moderately Pronated','Neutral','Supinated','Orthosis')) 
    # The measured leangth of the foot 
    clin_length = ndb.IntegerProperty() 
    # The measured width of the foot  
    clin_width = ndb.IntegerProperty()       
    # Provider notes - previous injury history 
    clin_inj = ndb.TextProperty()        
    # Provider notes - recommendations on footware 
    clin_recom = ndb.TextProperty()      
    # Regular physical activity [1] 
    clin_activ1 = ndb.StringProperty()       
    # Activity frequency: (daily, weekly) [1] 
    clin_freq1 = ndb.StringProperty(choices=('Daily','Weekly'))         
    # Regular physical activity [2] 
    clin_activ2 = ndb.StringProperty()       
    # Activity frequency: (daily, weekly) [2] 
    clin_freq2 = ndb.StringProperty(choices=('Daily','Weekly'))        
    # Regular physical activity [3] 
    clin_activ3 = ndb.StringProperty()       
    # Activity frequency: (daily, weekly) [3] 
    clin_freq3 = ndb.StringProperty(choices=('Daily','Weekly'))     

class Assessments(ndb.Model): 

# JW Recommendations 

    # JW consultant requested - can be overidden by consultant 
    assess_consultant = ndb.StringProperty() 
    # Consultant notes - general recommendation notes 
    assess_notes = ndb.TextProperty() 

# Recommended Shoe [1] 

    # Product ID/link 
    assess_pid1 = ndb.StringProperty()           
    # Category 
    assess_category1 = ndb.StringProperty()        
    # Brand 
    assess_brand1 = ndb.StringProperty()       
    # Model 
    assess_model1 = ndb.StringProperty()       
    # Size 
    assess_size1 = ndb.StringProperty()       
    # Width 
    assess_width1 = ndb.StringProperty()        

# Recommended Shoe [2] 

    # Product ID/link 
    assess_pid2 = ndb.StringProperty() 
    # Category 
    assess_category2 = ndb.StringProperty() 
    # Brand 
    assess_brand2 = ndb.StringProperty() 
    # Model 
    assess_model2 = ndb.StringProperty() 
    # Size 
    assess_size2 = ndb.StringProperty() 
    # Width 
    assess_width2 = ndb.StringProperty() 

# Recommended Shoe [3] 

    # Product ID/link 
    assess_pid3 = ndb.StringProperty()         
    # Category 
    assess_category3 = ndb.StringProperty()        
    # Brand 
    assess_brand3 = ndb.StringProperty()       
    # Model 
    assess_model3 = ndb.StringProperty()       
    # Size 
    assess_size3 = ndb.StringProperty()       
    # Width 
    assess_width3 = ndb.StringProperty() 

。この相談は、相談/相談相談ページで閲覧できます。このページ

http://localhost:8080/consults/view-consult?key=aghkZXZ-Tm9uZXIVCxIIQ29uc3VsdHMYgICAgIDIkwkM 

ユーザーインサート評価以前のように埋め込まれたキーを持つページ、/相談に送信されます「アセスメントを追加」と言ってリンクをクリックすることができます::urlはその者の相談キー組み込みを持って

http://localhost:8080/schedule/insert-assessment?key=aghkZXZ-Tm9uZXIVCxIIQ29uc3VsdHMYgICAgIDIkwkM 

質問(添付する正確に一つの評価を持つすべての相談)どのようにユーザーのヒットを提出したときに、私は1対1の関係でこれらのオブジェクトを結合しないと評価オブジェクトをポストです。

私の評価モデルに何かを追加する必要がありますか?

また、両方のオブジェクトのパラメータをビューの参照ページに表示する必要があります。

1のエンティティのために編集

class ViewConsultPage(webapp2.RequestHandler): 
    def get(self): 
     consult = ndb.Key(urlsafe=self.request.get('key')).get() 
     template = JINJA_ENVIRONMENT.get_template('/templates/view-consult.html') 
     template_values = { 
     'consult': consult 
     } 
     self.response.out.write(template.render(template_values)) 
    def post(self): 
     jw_consultant = self.request.get("jw_consultant") 
     jw_notes = self.request.get("jw_notes") 
     pid1 = self.request.get("pid1") 
     cat1 = self.request.get("cat1") 
     brand1 = self.request.get("brand1") 
     model1 = self.request.get("model1") 
     size1 = self.request.get("size1") 
     width1 = self.request.get("width1") 
     pid2 = self.request.get("pid2") 
     cat2 = self.request.get("cat2") 
     brand2 = self.request.get("brand2") 
     model2 = self.request.get("model2") 
     size2 = self.request.get("size2") 
     width2 = self.request.get("width2") 
     pid3 = self.request.get("pid3") 
     cat3 = self.request.get("cat3") 
     brand3 = self.request.get("brand3") 
     model3 = self.request.get("model3") 
     size3 = self.request.get("size3") 
     width3 = self.request.get("width3") 
     assessment = Assessments(id=consult.key.id(), 
           assess_consultant=jw_consultant, 
           assess_notes=jw_notes, 
           assess_pid1=pid1, 
           assess_category1=cat1, 
           assess_brand1=brand1, 
           assess_model1=model1, 
           assess_size1=size1, 
           assess_width1=width1, 
           assess_pid2=pid2, 
           assess_category2=cat2, 
           assess_brand2=brand2, 
           assess_model2=model2, 
           assess_size2=size2, 
           assess_width2=width2, 
           assess_pid3=pid3, 
           assess_category3=cat3, 
           assess_brand3=brand3, 
           assess_model3=model3, 
           assess_size3=size3, 
           assess_width3=width3) 
     assessment.put() 
+0

サイドノート:コードスニペットをMCVEにトリムすることができます:http://stackoverflow.com/help/mcve –

答えて

2

:あなたは他の利点の中で、一方のエンティティからの風その他の相互参照を行い、同じキーIDを、使用することができます1の関係。

例えば参照してください、:あなたのコードの例Relation Index Entities and Projections Query

  • re-using an entity's ID for other entities of different kinds - sane idea?
  • 第二例:/templates/view-consult.html

    • どこかにあなたがconsult」を渡したいですsキーストリングrepres entation connect_key_stringまたはその情報はあなたが直接そのIDを使用したり、他のように(connectエンティティのキ​​ーを復元したいpost()方法でpost()要求

    • で利用可能であるように、投稿フォームにも、そのキーID connect_idLinking to entity from listを投稿)し、キーのIDを取得する:

      connect_id = int(self.request.get("connect_id")) 
      assessment = Assessment(id=connect_id) 
      assessment.put() 
      

      または

      connect_key = ndb.Key(urlsafe=self.request.get('connect_key_string')) 
      assessment = Assessment(id=connect_key.id()) 
      assessment.put() 
      
+0

Danに感謝します。特定のエンティティを「再利用する」方法を理解しようとしています。 。それは私が2つのモデルにKeyPropertyを使って何らかのプロパティを追加する必要があるかのようなものですか? – TimothyAURA

+0

アセスメントエンティティを作成するときに、対応するコンサルタントのKeyIDと同じKeyIDを指定します。 'assessment = Assessment(id = consult.key.id())' 'assessment.put()' –

+0

それは試してみる。 – TimothyAURA

関連する問題