python - Caught AttributeError while rendering: 'unicode' object has no attribute '_default_manager' -



python - Caught AttributeError while rendering: 'unicode' object has no attribute '_default_manager' -

get error next practical django tutorial. have searched here , google , haven't found mentions of this, imagine it's going easy missing. exception in gambino_tags.py:

context[self.varname] = self.model._default_manager.all()[:self.num]

models.py

class entry(models.model): # entry types live_status = 1 draft_status = 2 hidden_status = 3 status_choices = ( (live_status, 'live'), (draft_status, 'draft'), (hidden_status, 'hidden'), ) # foreign key author = models.foreignkey(user) title = models.charfield(max_length=250, help_text='maximum 250 characters.') # bit of redundancy excerpt & excerpt_html , body & body_html, seems cleanest way seperate plain text , html excerpt = models.textfield(blank=true, help_text='add excerpt - short summary of post.') excerpt_html = models.textfield(editable=false, blank=true) body = models.textfield(help_text='add content of post.') body_html = models.textfield(editable=false, blank=true) pub_date = models.datetimefield(default=datetime.datetime.now) # slug prepopulated title in admin.py slug = models.slugfield(unique_for_date='pub_date', help_text="suggested value automatically generated title. must unique.") enable_comments = models.booleanfield(default=true) featured = models.booleanfield(default=false, help_text="make post featured. provide additional sorting.") status = models.integerfield(choices=status_choices, default=live_status) categories = models.manytomanyfield(category) tags = tagfield() # adds objects , live override liveentrymanager class above live = liveentrymanager() objects = models.manager()

gambino_tags.py

from django import template django.db.models import get_model def do_latest_content(parser, token): bits = token.contents.split() # checks create sure there 5 words in tag if len(bits) != 5: raise template.templatesyntaxerror("'get_latest_content' tag takes 4 arguments") model_args = bits[1].split('.') # checks create sure first argument appname.model name if len(model_args) != 2: raise template.templatesyntaxerror("first argument 'get_latest_content' must 'application name'.'model name' string") model = get_model(*model_args) # checks create sure model != none if model none: raise template.templatesyntaxerror("'get_latest_content' tag got invalid model: %s" % bits[1]) homecoming latestcontentnode(bits[1], bits[2], bits[4]) class latestcontentnode(template.node): def __init__(self, model, num, varname): self.model = model # convert num int self.num = int(num) self.varname = varname def render(self, context): # uses default manager entry.live.all() instances context[self.varname] = self.model._default_manager.all()[:self.num] homecoming '' register = template.library() register.tag('get_latest_content', do_latest_content)

base.html

{% load gambino_tags %} <h2>five latest entries:</h2> <ul> {% get_latest_content gambino.entry 5 latest_entries %} {% entry in latest_entries %} <li> <a class="list" href="{{ entry.get_absolute_url }}">{{ entry.title }}</a> posted {{ entry.pub_date|timesince }} ago. </li> {% endfor %} </ul> <h2>five latest links:</h2> <ul> {% get_latest_content gambino.link 5 latest_links %} {% link in latest_links %} <li> <a href="{{ link.get_absolute_url }}">{{ link.title }}</a> posted {{ link.pub_date|timesince }} ago. </li> {% endfor %} </ul>

thanks!

the model argument of node's __init__ string (or @ least, that's you're passing in), not model object.

bits = token.contents.split() ... homecoming latestcontentnode(bits[1], bits[2], bits[4]) ... class latestcontentnode(template.node): def __init__(self, model, num, varname): self.model = model ... context[self.varname] = self.model._default_manager.all()[:self.num]

perhaps meant...

return latestcontentnode(model, bits[2], bits[4])

?

python django

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -