Hi all,
I'm a Django newbie and am trying to write a simple blog application.
So far I've been able to define the initial models and add sample
blog posts using the Django admin interface.
Now I'm trying to build the views/templates. I'm having trouble
displaying the 'authors' ManyToManyField using a {% for %} block
in my template.
I tried the following inside the python interpreter.
::::::::::::::
>>> from mysite.weblog.models import Entry, Blog
>>> from tagging.models import Tag
>>> Entry.objects.count()
2L
>>> entries = Entry.objects.all()
>>> print entries
[<Entry: My first blog post>, <Entry: Django is cool>]
>>>
>>> entries[0].authors.all()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/home/djangouser/lib/python2.4/site-packages/django/db/models/query.py", line
106, in __repr__
return repr(self._get_data())
File
"/home/djangouser/lib/python2.4/site-packages/django/db/models/query.py", line
479, in _get_data
self._result_cache = list(self.iterator())
File
"/home/djangouser/lib/python2.4/site-packages/django/db/models/query.py", line
178, in iterator
select, sql, params = self._get_sql_clause()
File
"/home/djangouser/lib/python2.4/site-packages/django/db/models/query.py", line
493, in _get_sql_clause
joins2, where2, params2 = self._filters.get_sql(opts)
File
"/home/djangouser/lib/python2.4/site-packages/django/db/models/query.py", line
704, in get_sql
joins2, where2, params2 = val.get_sql(opts)
File
"/home/djangouser/lib/python2.4/site-packages/django/db/models/query.py", line
755, in get_sql
return parse_lookup(self.kwargs.items(), opts)
File
"/home/djangouser/lib/python2.4/site-packages/django/db/models/query.py", line
907, in parse_lookup
joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts,
opts.db_table, None)
File
"/home/djangouser/lib/python2.4/site-packages/django/db/models/query.py", line
1025, in lookup_inner
raise TypeError, "Cannot resolve keyword '%s' into field. Choices are: %s"
% (name, ", ".join(choices))
TypeError: Cannot resolve keyword 'authors' into field. Choices are: groups,
user_permissions, message, logentry, id, username, first_name, last_name,
email, password, is_staff, is_active, is_superuser, last_login, date_joined
::::::::::::::
I've also attached my 'models.py' file for reference.
Thanks,
Shankar
::::::::::::::
models.py
::::::::::::::
from django.db import models
from django.contrib.auth.models import User
from tagging.models import Tag
from comment_utils.moderation import CommentModerator, moderator
class Blog(models.Model):
title = models.CharField(maxlength=128)
tagline = models.TextField()
def __str__(self):
return self.title
class Admin:
pass
class Entry(models.Model):
title = models.CharField(maxlength=255)
summary = models.TextField()
text = models.TextField()
date_published = models.DateTimeField()
is_published = models.BooleanField(default=False)
enable_comments = models.BooleanField()
blog = models.ForeignKey(Blog)
authors = models.ManyToManyField(User)
tags = models.ManyToManyField(Tag)
def __str__(self):
return self.title
class Meta:
ordering = ['-date_published']
verbose_name_plural = "entries"
class Admin:
list_display = ('title', 'date_published', 'is_published')
class EntryModerator(CommentModerator):
auto_moderate_field = True
enable_field = 'enable_comments'
moderate_after = 0
moderator.register(Entry, EntryModerator)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---