Okay Nick so your help really made a big difference. The generic view and urlconf helped a lot.
Well I didn't figure out how to do Melvyn's recommendation but I was able to implement this another way. It's good but not perfect.
from django.db import models
from django.forms import ModelForm
class Contributor(models.Model):
name = models.CharField(max_length=30)
lowername = models.CharField(max_length=30)
title = models.CharField(max_length=60)
bio = models.CharField(max_length=5000)
website = models.URLField()
def __unicode__(self):
class ContributorForm(ModelForm):
class Meta:
model = Contributor
Basically, my key was to add another field called lowername. This field would hold the lowercase version of the contributors name. So for me it is "jjzolper". By doing this with your help I was able to make it happen. And continuing on:
- about contributors (the page that lists all contributors so pulls it out of the database:
{% extends "base.html" %}
{% block HTMLTitle %}<title>About</title>{% endblock %}
{% block CSSFiles %}
<!-- Standard CSS Files -->
<!-- Standard CSS Files -->
{% endblock %}
{% block JSFiles %}
<!-- Standard JavaScript Files -->
<!-- Standard JavaScript Files -->
{% endblock %}
{% block content %}
<div id="content">
<div id="main">
</div>
<div class="clear"></div>
</div>
{% endblock %}
After having created this new field in the database I could call that field as the relevant URL! The second key.
Then it was simple from there on out with your code.
the urlconf you described:
- urls.py
(r'^about/contributors/(?P<contributorname>[a-zA-Z]+)$', 'madtrak.about.views.contributor'),
That value like you said is passed through this thing. It is sent to the view for a singular contributor:
- about views.py
def contributor(request, contributorname):
contributor_object = Contributor.objects.filter(lowername = contributorname)
return render_to_response('contributor.html', {'Contributor': contributor_object}, context_instance = RequestContext(request))
It tests to see based on the url for the request which entry corresponds to it.
about contributor.html (singular so the relevant contributor)
{% extends "base.html" %}
{% block HTMLTitle %}<title>About {{ Contributor.name }}</title>{% endblock %}
{% block CSSFiles %}
<!-- Standard CSS Files -->
<!-- Standard CSS Files -->
{% endblock %}
{% block JSFiles %}
<!-- Standard JavaScript Files -->
<!-- Standard JavaScript Files -->
{% endblock %}
{% block content %}
<div id="content">
<div id="main">
<ol>
{% for Contributor in Contributor %}
<ul>
<li>Name: {{ Contributor.name }}</li>
<li>Title: {{ Contributor.title }}</li>
<li>Bio: {{ Contributor.bio }}</li>
<li>Website: {{ Contributor.website }}</li>
</div>
<div class="clear"></div>
</div>
{% endblock %}
Thanks again for the great advice. Currently this is my best implementation of my about contributor page. I really appreciate your kind words and help when doing this.
If there is a better way I'm all ears! But this is what I'm going with for the time being!
Thanks so much,
JJ