Opened 17 years ago
Closed 17 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: | dev |
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 |
Description
I'm trying to write a wiki-like app and use SVN revision 7186.
models.py:
class Article(Model): class Admin: pass def __unicode__(self): return str(self.pk) def get_absolute_url(self): return "/pages/" + self.pk + "/" class ArticleEdit(Model): author = ForeignKey(User, related_name = "contributions") [...all other data...] article = ForeignKey(Article, related_name = "edits")
views.py:
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, {{ article.pk }}
always returns 1 and {{ article.get_absolute_url }}
doesn't exist.
2) http://code.djangoproject.com/ticket/1972
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.
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.