Opened 11 years ago

Closed 11 years ago

#6688 closed (invalid)

Methods of fieldless model can't be called in templates

Reported by: sam_cel Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I'm trying to write a wiki-like app and use SVN revision 7186.

class Article(Model):
	class Admin:
	def __unicode__(self):
		return str(
	def get_absolute_url(self):
		return "/pages/" + + "/"

class ArticleEdit(Model):
	author = ForeignKey(User, related_name = "contributions")
	[...all other data...]
	article = ForeignKey(Article, related_name = "edits")

def index(request):
        article = Article.objects.all()[0]
        return render_to_response("index.html", { "article" : article, })

The Article model is just used to tie the edits together.
I ran into two problems:

1) when I'm passing an Article-object to a template, {{ }} always returns 1 and {{ article.get_absolute_url }} doesn't exist.

That ticket was WONTFIXed, but obviously people keep running into this problem. I can't think of any clean way to model the above scenario with django, so maybe ticket 1972 should be reconsidered as well.

Change History (1)

comment:1 Changed 11 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

Questions like this are probably more appropriate for the django-users list, since there's a fair chance it's going to be problems with your code. There are no bugs here.

  1. is always the same because you're always selecting the same object.
  2. get_absolute_url() contains an error (you're concatenating strings and ints), so the template will return nothing when access it.
  3. Asking for #1972 to be reconsidered is not done by opening another ticket. Please, read contributing.txt for details on how to have a wontfix'ed ticket reconsidered.
Note: See TracTickets for help on using tickets.
Back to Top