Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:30:24+00:00 2026-06-12T06:30:24+00:00

I am new to Django and trying to make a basic website and having

  • 0

I am new to Django and trying to make a basic website and having a few difficulties getting the relevant record for a page.

Models.py

import datetime
from django.db import models
from django.conf import settings
from ckeditor.fields import RichTextField
from markdown import markdown

class LiveEntryManager(models.Manager):
      def get_query_set(self):
      return super(LiveEntryManager,self).get_query_set().filter(status=self.model.LIVE_STATUS)


class Page(models.Model):
      LIVE_STATUS = 1
      HIDDEN_STATUS = 2
      STATUS_CHOICES = (
            (LIVE_STATUS, 'Live'),
            (HIDDEN_STATUS, 'Hidden'),
       )
      title = models.CharField(max_length=250, help_text='Max 250 characters.')
      slug = models.SlugField(unique=True, help_text='Suggested automatically generated from the title. Must be unique') 
      description = RichTextField()
      description_html = models.TextField(editable=False, blank=True) 
      status = models.IntegerField(choices=STATUS_CHOICES, default=LIVE_STATUS, 
                           help_text="Only pages with live status will be publicly displayed")

      def save(self, force_insert=False, force_update=False):
          self.description_html = markdown(self.description)
          super(Page, self).save(force_insert, force_update)

      def get_record(self):
          return self.objects.get()

      #Managers
      live = LiveEntryManager()
      objects = models.Manager()

      class Meta:
            ordering = ['title']
            verbose_name_plural = "Pages"

      def __unicode__(self):
          return self.title

      def get_absolute_url(self):
          return "/%s/" % self.slug

class Image(models.Model):
      page = models.ForeignKey(Page)
      name = models.CharField(max_length=250)
      image = models.ImageField(upload_to='gallery')

      class Meta:
            ordering = ['name']

      def __unicode__(self):
          return self.name

And Views.py

from django.shortcuts import get_object_or_404, render_to_response
from django.views.generic.list_detail import object_list
from mainsite.models import Page, Image


def home(request):
    return render_to_response('templates/home.html')


def page(request, slug):
    one_page = get_object_or_404(Page, slug=slug)
    return render_to_response('templates/page/page.html',
                          { 'object_list': one_page.get_record() })

and Urls.py

urlpatterns = patterns('',
   # Examples:
   url(r'^$', 'mainsite.views.home', name='home'),
   # url(r'^disability/', include('disability.foo.urls')),
   url(r'^page/(?P<slug>[-\w]+)/$', 'mainsite.views.page'),
   # Uncomment the admin/doc line below to enable admin documentation:
   # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
   url(r'^grappelli/', include('grappelli.urls')),
   # Uncomment the next line to enable the admin:
   url(r'^admin/', include(admin.site.urls)),

)

What I want to do is to be able to go to say /page/test and get the title, description and image for that object only. I know how to get all objects and display them in a template but cannot figure out how to get a single record and would be grateful of some help.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:30:25+00:00Added an answer on June 12, 2026 at 6:30 am

    Where’d you get get_record() from? The return value of get_object_or_404 is a model instance. There’s nothing else to “get”, just pass the instance to your context. And, don’t use object_list as a context name. Not only is this an instance, not a list or queryset, but that name is most often used with pagination, and you’ll simply create confusion in your code if you’re not actually paginating anything.

    return render_to_response('templates/page/page.html', {
        'one_page': one_page,
    })
    

    Then in your template:

    <h1>{{ one_page.title }}</h1>
    <img src="{{ one_page.image.url }}" alt="">
    <p>{{ one_page.description }}</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im new to django and trying to make a user registration form with few
I'm relatively new to Django, and am trying to make some changes to Django's
i'm new to django and im trying add a user using django admin page.
I'm very new to Django. In my website I was trying to do something
I'm relatively new to Django and trying to create a page, where I ask
I am trying to use Django's generic views to make a user registration page.
i'm new to django, i'm trying to make a class-based views where i can
I am new to django and trying to use django-messages to add inbox/compose/outbox/trash functionality
I'm new to Django and just trying to submit a form using ModelForms to
i'm fairly new to django and just trying a couple simple experiments to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.