Hello,
I am writing a simple datastore query. I am using django templates in
the project.
Here is my model:
class Projects(db.Model):
name = db.StringProperty()
description= db.StringProperty(multiline=True)
Completed=db.BooleanProperty()
class ProjectImages(db.Model):
reference = db.ReferenceProperty(Projects)
description=db.StringProperty()
src=db.StringProperty()
The data is populated using DataStore:
def initializeDB(request):
project1 = Projects(name="Automotive Surface Study",
type="Here I designed a parametric automotive surface that
can be optimized for reduced drag. The surface was modeled in CATIA
and the analysis was done in COSMOS FlowWorks.",
completed=True)
project1.put()
img1=ProjectImages(reference=project1,description="completele
parameterization",
scr="http://farm3.static.flickr.com/
2661/3778830933_65338fba7c.jpg")
img2=ProjectImages(reference=project1,description="Design 3",
scr="http://farm3.static.flickr.com/
2609/3778819245_b07ca82e54.jpg")
img3=ProjectImages(reference=project1,description="Design 6",
scr="http://farm3.static.flickr.com/
2663/3778821521_1bdefff042.jpg")
img4=ProjectImages(reference=project1,description="Design 11",
scr="http://farm4.static.flickr.com/
3418/3779632902_d2d4cee465.jpg")
img5=ProjectImages(reference=project1,description="Design 17",
scr="http://farm3.static.flickr.com/
2493/3779635394_11a5323995.jpg")
img6=ProjectImages(reference=project1,description="Design 3",
scr="http://farm4.static.flickr.com/
3524/3778823879_ce572e1547.jpg")
img1.put()
img2.put()
img3.put()
img4.put()
img5.put()
img6.put()
return HttpResponse("")
Then here is the link that is clicked on
http://localhost:9999/projects/agd2cmFvNDIzcg4LEghQcm9qZWN0cxgEDA/
in the url.py, this maps to:
(r"projects/(.*)/$", 'views.projectsSelect'),
Then once someone accesses the line, it takes them to this function:
def projectsSelect(request, input_key):
t = get_template('projects.html')
p=Projects.all()
last_key = db.Key(input_key)
sp=Projects.get(last_key)
images=ProjectImages.ancestor(last_key)
#i have also tries this
#img=ProjectImages("WHERE reference = :select_key", select_key=sp
[0])
#but that does not work
html = t.render(Context({'projects': p, "description": sp
[0].description, "img":images}))
return HttpResponse(html)
Then the html template is:
<div class="project_list">
{% for project in projects %}
<a href="/projects/{{project.key}}">{{project.name}}</a><br>
{% endfor %}
</div>
<div class="project">
<div class="project_images">
<script>
gNumberOfImages = {{ images.count }};
gImages = new Array(gNumberOfImages);
var count=0;
{% for image in images %}
gImages[count] = "{{image.src}}";
count++;
{% endfor %}
setInterval("nextSlide()",gSlideshowInterval * 1000);
</script>
<IMG SRC="" BORDER=0 width="550px" NAME="slide">
</div>
<div class="project_description">
{% for project in description %}
{{project.description}}
{% endfor %}
</div>
</div>
The two queries don't work. .get and the ancestor functions are
wrong. I am not using the reference and get() functions well. I need
help. I am new to the app engine and python.
I am not sure if this explains my problem completely. If someone has
the time, I can send them the code in a zip file.
Thank you,
Venkat Rao
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---