Sorry if this is a dumb way to ask this... I have a generic list view for the homepage of a site, and would like to use a "homepage" model for informative text on that same page...is it possible? Thanks for your help.
models.py
from django.db import models
class School(models.Model):
school_name = models.CharField(max_length=250, help_text='Maximum 250 characters.')
slug = models.SlugField(unique=True)
def __unicode__(self):
return self.school_name
def get_absolute_url(self):
return "/schools/%s/" % self.slug
class Student(models.Model):
name = models.CharField(max_length=250, help_text='Maximum 250 characters.')
slug = models.SlugField(unique=True)
mugshot = models.ImageField(upload_to='mugshots')
school = models.ForeignKey(School)
honor = models.TextField()
def __unicode__(self):
return self.name
def get_absolute_url(self):
return "/student/%s/" % self.slug
class Homepage(models.Model):
title = models.CharField(max_length=250, help_text='Maximum 250 characters.')
content = models.TextField()
def __unicode__(self):
return self.title
urls.py
from django.conf.urls.defaults import *
from achievers.apps.students.models import School, Student
from achievers.apps.students.views import hello
from django.contrib import admin
admin.autodiscover()
info_dict = {
'queryset': School.objects.all(),
'extra_context': {'school_list': School.objects.all,}
}
info_dict2 = {
'queryset': Student.objects.all(),
'template_name': 'students/student_detail.html',
'extra_context': {'student_detail': Student.objects.all}
}
urlpatterns = patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'static'}),
(r'^student/(?P<slug>[-\w]+)/$', 'django.views.generic.list_detail.object_detail', info_dict2),
(r'^students/(?P<slug>[-\w]+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
(r'^$', 'django.views.generic.list_detail.object_list', info_dict),
(r'^admin/', include(admin.site.urls)),
(r'^hello/', hello),
)