[Tutor] A Django Beginner View Question
Alasdair Macmillan
al.macmillan at me.com
Wed Jul 28 20:59:22 CEST 2010
Hi
I am building my first Django site which has a lot of effectively 'static' pages where I just want to make the meta data and text editable.
The model is
models.py
class About(models.Model):
page_title = models.CharField(max_length=900, help_text='Text at top of browser window')
meta_keywords = models.CharField(max_length=900, help_text='Keywords (for SEO)')
meta_description = models.CharField(max_length=160, help_text='Description (for SEO)')
logo_header = models.CharField(max_length=900, help_text='H1 Header (for SEO)')
header = models.CharField(max_length=60)
body = models.TextField()
last_updated = models.DateTimeField(default=datetime.datetime.now, primary_key=True)
class Meta:
get_latest_by = "last_updated"
verbose_name_plural = "About Page"
# managed = False
def __unicode__(self):
return self.title
I'm trying to understand how to either write a model that only allows a single entry or write a view that will take either a single entry or the most recent entry.
views.py
def about(request):
return render_to_response('about.html',
{ 'About' : About.objects.latest() })
urls.py
(r'^about/$', 'harkproject.cms.views.about'),
Much appreciated
Al Macmillan
More information about the Tutor
mailing list