Thanks in advance for anyone answering this thread.
I am building a DB of local government representatives. My goal is to
spit out a general list of the reps and a detailed bio page for each
rep.
The URL structure I would like to have is 'government/reps/list' for a
list of all of the Reps and 'government/reps/
REPSLASTNAME_REPSFIRSTNAME' for the single bio view.
Here is my model:
class Rep(models.model):
<There is a bunch of dictionaries of the choices that go right here
that I'm ommitting>
Type = models.CharField(max_length=100, choices=Type_Choices,
blank=True)
Last_Name = models.CharField('Last Name', max_length=100,
blank=True)
First_Name = models.CharField('First Name', max_length=100,
blank=True)
Position = models.CharField('Position', help_text="Only used for
non-council City and Local officials", max_length=100, blank=True,
choices=Position_Choices)
Party = models.CharField(max_length=3, choices=Party_Choices,
blank=True)
District = models.IntegerField(help_text="For State, Federal and
County Commissioners", blank=True, null=True)
Ward = models.IntegerField(help_text="For City Councils",
blank=True, null=True)
City = models.CharField(max_length=100, blank=True)
Phone = models.CharField(max_length=15, help_text="Use the form
xxx-xxx-xxxx", blank=True)
Email = models.EmailField(max_length=100, blank=True)
Contact_URL = models.URLField(max_length=200, blank=True)
DOB = models.DateField('Date of Birth',blank=True, null=True)
Gender = models.CharField(blank=True, max_length=2,
choices=Gender_Choices)
Begin_Serve = models.IntegerField('Began Serving in', blank=True,
null=True)
End_Serve = models.IntegerField('Term Limited in', blank=True,
null=True)
MugShot = models.ImageField('Mug Shot Upload', help_text="images
are to be no larger that 150x200", storage=s3_storage,
upload_to='newsok/images/Government/images/mugs', height_field=None,
width_field=None, max_length=300, blank=True)
Committees = models.ManyToManyField('Committees', blank=True)
Approp_Committee = models.ManyToManyField('Approp_Committees',
blank=True)
def __unicode__(self):
return u"%s, %s" % (self.Last_Name, self.First_Name)
class Meta:
abstract = False
Here is my view:
from Government.Reps.models import *
from django.shortcuts import render_to_response
from django.http import Http404
def index(request):
rep_list_view = Rep.objects.all().order_by('Last_Name')
return render_to_response('Government/repsAll.html', {'allReps':
rep_list_view})
def detail(request, (Last_Name, First_Name)):
try:
r = Rep.objects.all().order_by('Last_Name', 'First_Name')
except Rep.DoesNotExist:
raise Http404
return render_to_response('Government/repsSingle.html',
{'singleRep': r})
Here is my URL conf:
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^Government/', include('Government.foo.urls')),
# Uncomment the admin/doc line below and add
'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^reps/(P?<Last_Name>_<First_Name>\d+)/$',
'Government.Reps.views.detail'),
I think that I am either overthinking this or way UNDER thinking it.
This is my first go at a template being called via variables passed in
the URL. I have a good background in templates and the models portion
of django but am sorely lacking in my understanding of views and URL
confs.
Thanks again,
Nick
--
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.