This is a good idea for consistency, but did nothing to fix the problem. Is the a Category class somewhere in Django that I don't know about that could be conflicting??
On Feb 3, 2008 8:15 AM, Ned Batchelder <[EMAIL PROTECTED]> wrote: > It looks like you are using different styles of importing your models in > different places: > > views.py: from weblog.models import Category, Entry > blog_extras.py: from lukenslanguages.weblog.models import Entry > > I can't quite see how that leads to your "cannot import name Category" > error, but I'd try making those imports the same. Your imports may be > getting tangled up in relative imports meaning different things from > different places. I'm guessing the directory above lukenslanguages is on > your PYTHONPATH, so make them all start from lukenslanguages like the > blog_extras.py imports do. > > --Ned. > > [EMAIL PROTECTED] wrote: > > Hi Ned, > > I figured as much, but since without the 'try' made no difference, I > thought I'd give it a whirl.... here is the source. > 'lukenslanguages' is the project directory. > > #lukenslanguages/weblog/models.py > > from django.db import models > > class Category(models.Model): > name = models.CharField(maxlength=20) > url = models.SlugField(prepopulate_from=("name",)) > > def __str__(self): > return self.name > > class Admin: > pass > > class Entry(models.Model): > title = models.CharField(maxlength=100) > url = models.SlugField(prepopulate_from=("title",)) > category = models.ForeignKey(Category) > body = models.TextField() > date = models.DateField() > > def __str__(self): > return self.title > > class Admin: > pass > > #lukenslanguages/urls.py > > from django.conf.urls.defaults import * > from lukenslanguages import views > > urlpatterns = patterns('', > (r'^admin/', include('django.contrib.admin.urls')), > (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', > {'document_root': 'C:/django-0.96.1/lukenslanguages/templates/'}), > (r'(^[a-z-]+)/$', views.entry_list), > ) > > #lukenslanguages/views.py > > from django.shortcuts import render_to_response > from weblog.models import Category, Entry > from django.template import loader, RequestContext > from context_processors import menu_list > > def entry_list(request, category): > c = Category.objects.get(url=category) > entries = c.entry_set.all() > return render_to_response('weblog/blogentry_list.html', > {'entries': entries, 'category':c.name, > 'title': c.name}, > > context_instance=RequestContext(request, processors=[menu_list])) > > #lukenslanguages/context_processors.py > > from weblog.models import Category > > def menu_list(request): > "A context processor that serves the categories for use as menu > items" > return { > 'categories': Category.objects.all() > } > > #lukenslanguages/weblog/templatetags/blog_extras.py > > from django.template import Library > from lukenslanguages.weblog.models import Entry > > register = Library() > > @register.filter > def category_url(entry_id): > e = Entry.objects.get(id=entry_id) > return e.category.url > > I think that this is all of the pertinent code. If you would like to > see anything else, please let me know. > > Thank you, > Jonathan > On Feb 3, 7:43 am, Ned Batchelder <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> > wrote: > > > When Kenneth suggested "try: @register.filter", he meant, try: > "@register.filter", that is, the word "try:" was not meant to go in the > file. > > You may have an import problem in your models file. Can you post more > of the source so that we can take a look? > > --Ned.http://nedbatchelder.com/blog > > > [EMAIL PROTECTED] wrote: > > > Thanks for the input. > > > try: @register.filter <--- without the '()' > > > so long as this is in the file, I get a syntax error if I run the file > from the command prompt, with the caret pointing to the '@', with or > without the '()'. I get the same thing if I do this after the > function: > > > try: register.filter(category_url) > > > If there is no 'try' in the module, I can import the the filter > function in the python shell and it works correctly. > I am not sure what else you might have meant by running from the > shell. > Thanks for your help. > > > Jonathan > > > -- > > > regards > kghttp://lawgon.livejournal.comhttp://nrcfosshelpline.in/web/ > Foss Conference for the common man:http://registration.fossconf.in/web/ > > -- > Ned Batchelder,http://nedbatchelder.com > > > -- > Ned Batchelder, http://nedbatchelder.com > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---