Wish it were that easy. The app is installed, and it works everywhere
else. If I take out the {% load bookmarks %} from the template, the
rest of the app works fine. I have a view that bookmarks an object,
and it checks if a user has bookmarked that object first.

This is how I did it in the view (part of another app--a database of
online news tools):

def bookmark_tool(request, category_id, tool_id):
    "Bookmarks a tool"
    user = get_object_or_404(User, pk=request.user.id)
    tool = get_object_or_404(Tool,
                             category__slug__iexact=category_id,
                             slug__iexact=tool_id)
    b_list = [b.content_object for b in user.bookmark_set.all()]
    if tool not in b_list:
        Bookmark.objects.create(content_object=tool, user=user)
    return HttpResponseRedirect(tool.get_absolute_url())

And that works exactly as it should.

On Oct 15, 11:21 am, RyanP <[EMAIL PROTECTED]> wrote:
> Seems like the problem's got to be with the "from bookmarks.models
> import Bookmark" line.
>
> The "No module named models" part of your error message suggests that
> Django doesn't know about your bookmarks/models.py ... if that app is
> on your Pyton path, any chance that it's just not listed in your
> INSTALLED_APPS?
>
> On Oct 15, 10:17 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > The templatetag file is indeed called bookmarks.py. I thought of that,
> > tried renaming it as bookmark_tags.py, and got the same error. I'll
> > add that the bookmarks app lives on my python path, not in any
> > particular project, since I'm trying to make this as reusable as
> > possible.
>
> > At one point, I tried just removing the line 'from bookmarks.models
> > import Bookmark', and the library loaded, but it hit an error
> > (correctly) when I tried use it, saying Bookmark wasn't defined.
>
> > On Oct 14, 11:45 pm, Daniel Roseman <[EMAIL PROTECTED]>
> > wrote:
>
> > > On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > > I have a simple bookmarks model based on the one in James Bennett's <a
> > > > href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> > > > r=130">Cab</a> application. I'm using a generic relation so it can
> > > > live in its own app and a user can bookmark any object on the site
> > > > (I'm planning on reusing this app on a couple projects). I'm running
> > > > into a problem creating an {% if_bookmarked %}templatetag.
>
> > > > When I load the tag library I get this error: 'bookmarks' is not a
> > > > valid tag library: Could not loadtemplatelibrary from
> > > > django.templatetags.bookmarks,Nomodulenamedmodels
>
> > > > Here's what the tagmodulelooks like:
>
> > > <snip>
>
> > > > The bookmarking model works fine on its own, and I've gotten the
> > > > functions in thetemplatetag to work in isolation in the interpreter,
> > > > but when I load the tag library it breaks thetemplate. What am I
> > > > missing here?
>
> > > Is the templatetag file itself called bookmarks.py, by any chance? If
> > > so, the code may be trying to import that rather than the top-level
> > > bookmarks directory. Try renaming the file, although I would also
> > > recommend using full paths when importing (ie from
> > > projectname.bookmarks.models).
> > > --
> > > DR
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to