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 8774785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:39:15+00:00 2026-06-13T18:39:15+00:00

I’m trying to costomise the display in the admin interface. I need one of

  • 0

I’m trying to costomise the display in the admin interface. I need one of the fields to display the name and date submitted for photo sharing site I’m creating, but I keep getting the following error:

global name 'datetimeConvertToHumanReadable' is not defined

Here’s the full traceback: http://dpaste.com/822073/

My code

Model:

class Design(models.Model):
    designer_id = models.ForeignKey(User)
    date_submitted = models.DateTimeField()
    title = models.CharField(max_length=70)
    description = models.TextField()
    photo = models.FileField(upload_to='design_photos')

    def image_thumb(self):
        return '<img src="/media/%s" width="100" height="100" />' % (self.photo)
    image_thumb.allow_tags = True

    def datetimeConvertToHumanReadable(dt):

        # convert passed datetime to timestamp
        dt_stamp = dt.strftime("%s")

        # convert current datetime to timestamp
        now = datetime.datetime.now()
        now_stamp = now.strftime("%s")

        # find difference between the two
        delta = int(now_stamp) - int(dt_stamp)

        # convert to (seconds ago, minutes ago, hours ago, etc...)
        if (delta < 60):
            return str(delta) + " seconds ago"
        elif (delta < 3600):
            return str(delta/60) + " minutes ago"
        elif (delta < 86400):
            return str(delta/3600) + " hours ago"
        elif (delta < 31536000):
            return str(delta/86400) + " days ago"
        else:
            return str(delta/31536000) + " years ago"

    def name_and_submitted(self):
        date_submitted = datetimeConvertToHumanReadable(date_submitted) 
        return '<div>%s<br />submitted %s ago</div>' % (self.designer_id, self.date_submitted)

    def __unicode__(self):
        return self.title

Admin.py:

class DesignAdmin(admin.ModelAdmin):

    list_display = ('image_thumb', 'title', 'description', 'name_and_submitted')

The image_thumb method works fine to display a thumbnail in the field, but the name_and_submitted method throws up the error. Any ideas?

  • 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-13T18:39:17+00:00Added an answer on June 13, 2026 at 6:39 pm

    Just pass the self argument. That should solve the problem

    def datetimeConvertToHumanReadable(self):
        dt = self.date_submitted
        # rest of your code goes here
    

    The problem is that, when you are not passing the self argument, the function is not attached to the class and not callable through a model object. list_admin_display actually access the model instance and calls the function. In your case, it would be something like design_object.datetimeConvertToHumanReadable where design_object is each model instance displayed in the admin page. The argument dt is not passed as an argument, so you need to extract it within your function.

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
In my XML file chapters tag has more chapter tag.i need to display chapters
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.