Karthika_g 0 Newbie Poster

Hello,

Please let me know how should we get the id of an entity and put it in the another entity. I have two entity User and Track.

I tried the below code I couldn't make.
Please help!

class Review(webapp2.RequestHandler):

        template = JE.get_template('templates/Review.html')
        self.response.out.write(template.render())


    def post(self):
        n = self.request.get('user_name')
        t = self.request.get('track_name')
        a = self.request.get('artist_name')
        c = self.request.get('comment')
        r = int(self.request.get('rating'))
        q = db.Gqlquery("SELECT track_name from Track")
        for msg in q:
            if t!=msg:
                trk = models.Track(track_name = t, artist_name = a)
                trk.put()
            else:
                self.response.out.write("<h3>Already track exists</h3>")

        #query = db.GqlQuery("SELECT __key__ FROM Track WHERE track_name = :1, t)
        #for m in query:
            #self.response.write('%s' %m)
        usr =  models.User(user_name = n, content = c, rating = r)
        usr.put()



        self.response.out.write("<h3>Thank you for posting</h3>")
        #self.redirect('/')

My model classes are:

class User(db.Model):
    user_name = db.StringProperty(multiline=True)
    track_id = db.StringProperty(multiline=True)
    content = db.StringProperty(multiline=True)
    rating = db.IntegerProperty()
    time = db.DateTimeProperty(auto_now_add=True)

class Track(db.Model):
    track_name = db.StringProperty(multiline=True)
    artist_name = db.StringProperty(multiline=True)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.