Daniel
You helped a lot. You are right that my code wasn't clear. I only
extracted snipets and forgot bits, e.g. talk _title and speaker_title
which are in the model but not in what I reported. Frankly, all I'm
trying to do right now is experiment to learn how this works.
Eventually, I have a couple of projects in mind, the first being
something to generate HTML files for a web site based on content in a
database.
You are right, the root cause is that I was not yet understanding how
to access the models and part of my learning is deaing with ojects in
Python. With your key help, it now works and I see the light.
I learned:
1. create the objects (one record from the database table) by
my_objectname=[Classname].objects.all()[N] where N is the record
number.
2. when change the data model, I have to restart the python shell ...
on the to-do list is to learn how to redefine the data model.
3. in the template, use the objectname in the double brackets, e.g.
{{ my_objectname.date }} and {{ my_objectname.test }}
4. calling render_to_response is differnt than I thought!
print render_to_response('mtg_summary.html',{'my_meeting':my_meeting})
Question: in the context of this example, in
{'my_meeting':my_meeting}), what are these two things opposite of the
colon?
> It's not at all clear from the code what you're trying to do.
> talk_title and speaker_title aren't defined anywhere in the code
> you've given us, but I'm not even sure if those are the 'custom
> fields' you're referring to.
>
> What's more, the code you've given us would not be capable of
> producing the output you've shown, so this clearly isn't the actual
> code. We would need to see the actual view and template code - it's
> best if you paste it at dpaste.com and give us a link.
>
> If by 'custom fields' you mean methods on the model, like your test()
> example, you wouldn't expect the values() method to show them. It will
> only show the actual model fields.
>
> I think you're misunderstanding how to access models in your code and
> templates. values() isn't the normal way of doing it - really, you
> just want to be passing an instance of Tmeeting to your template and
> then using normal dot notation to access the values.
>
> For example:
>
> my_meeting = Tmeeting.objects.all()[0]
> print my_meeting.date
> print my_meeting.speaker
> print my_meeting.test()
> print render_to_response('mtg_summary.html',
> {'my_meeting':my_meeting})
>
> and in the template:
> <p>Talk_title: {{ my_meeting.talk }}</p>
> <p>Speaker: {{ my_meeting.speaker }}</p>
> <p>Speaker_Title:{{ my_meeting.speaker_title }}</p> {# where is this
> coming from? #}
> <p>test: {{ my_meeting.test }}</p>
>
> etc.
>
> (Note that the convention is to have lower case names for model fields
> and methods.)
>
> --
> DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---