Note that there are some explanatory texts on larger screens.

plurals
  1. PO'str' object has no attribute 'get_ordering_field_columns' django error
    text
    copied!<p>I've searched for a while trying to figure this out. I'm a python newbie so if this is a stupid question I apologize in advance. </p> <p>I'm trying to implement an inter-staff message system with threads (not pthread type threads, but a comment thread). I understand how to make such a system from a software design point of view, but I have no idea what the error in the title means or how to fix it. I've managed to fix all of my other errors via google and stackoverflow, but this one remains a mystery.</p> <p>urls.py</p> <pre><code>urlpatterns = patterns('', # Examples: url(r'^home/bam$', 'fblmanager.views.home.bam', name='bam'), url(r'^admin/comments/commenttitle/$', 'comments.admin_views.comments', name='comments'), # url(r'^emailinterface/', include('emailinterface.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), (r'^grappelli/', include('grappelli.urls')),) </code></pre> <p>admin_views.py</p> <pre><code> from comments.models import * from django.template import RequestContext from django.shortcuts import render_to_response from django.contrib.admin.views.decorators import staff_member_required def comments(request): return render_to_response( 'comment_list.html', ) </code></pre> <p>comments/models.py</p> <pre><code>from django.db import models from django.contrib import admin from django.contrib.auth.models import User from django import template class CommentMessage(models.Model): id = models.AutoField(primary_key = True) comment = models.TextField('Comment') add_timestamp = models.DateTimeField('Date Added', auto_now = True, auto_now_add = False) update_timestamp = models.DateTimeField('Date Of Last Update', auto_now = True, auto_now_add = True) user = models.ForeignKey(User) def __unicode__(self): return '%s' % (self.comment) class Meta: app_label = 'comments' class CommentTitle(models.Model): id = models.AutoField(primary_key = True) title = models.CharField('Comment Title', max_length = 254) comment_message = models.ManyToManyField(CommentMessage) add_timestamp = models.DateTimeField('Date Added', auto_now = True, auto_now_add = False) update_timestamp = models.DateTimeField('Date Of Last Update', auto_now = True, auto_now_add = True) user = models.ForeignKey(User) def __unicode__(self): return '%s' % (self.title) class Meta: app_label = 'comments' class CommentTitleAdmin(admin.ModelAdmin): register = template.Library() def changelist_view(self, request, extra_context = None): return super(CommentTitleAdmin, self).changelist_view(request, extra_context) @register.inclusion_tag("admin/change_list_results.html") def result_list(cl): #Displays the headers and data list return {'cl' : cl, 'result_hidden_fields' : list(result_hidden_fields(cl)), 'result_headers' : list(result_headers(cl)), 'results' : list(results(cl))} #return_list = register.inclusion_tag("admin/change_list_results.html")(result_list) list_display = ('title', ) class Meta: app_label = 'comments' </code></pre> <p>comment_list.html/</p> <pre><code>{% extends "admin/change_list.html" %} </code></pre> <p>EDIT:</p> <p>Hopefully, this will help. If you need any more information I'll post it. There's a lot of stuff and being a python newbie I'm not really sure what's all relevant and what's not to answering the question. I should have included this though sorry about the inconvenience.</p> <p>I'm guessing the error is being caused by me not doing something I'm suppose to be doing in either the CommentTitle method or the CommentTitleAdmin method.</p> <p>admin.py</p> <pre><code>from django.contrib import admin from comments.models import * admin.site.register(CommentTitle, CommentTitleAdmin) admin.site.register(CommentMessage) </code></pre> <p>The error</p> <pre><code> Error during template rendering In template /usr/local/lib/python2.6/dist-packages/django_grappelli-2.4.0a1-py2.6.egg/grappelli/templates/admin/change_list.html, error at line 215 </code></pre> <p>From the change_list.html file (https://github.com/sehmaschine/django-grappelli/blob/grappelli_2_4/grappelli/templates/admin/change_list.html)</p> <pre><code> {% block result_list %} {% result_list cl %} # throws the error {% endblock %} </code></pre> <p>EDIT 2:</p> <p>I took out the grappelli app to see if it would make a difference and I get a different error.</p> <pre><code>NoReverseMatch at /admin/comments/commenttitle/ Reverse for 'app_list' with arguments '()' and keyword arguments '{'app_label': ''}' not found. Error during template rendering In template /usr/local/lib/python2.6/dist-packages/django/contrib/admin/templates/admin/change_list.html, error at line 44 &amp;rsaquo; &lt;a href="{% url 'admin:app_list' app_label=cl.opts.app_label %}"&gt;{{ app_label|capfirst|escape }}&lt;/a&gt; </code></pre> <p>SOLUTION:</p> <p><s>I guess in the view {% block content %} {% endblock %} is required. For some reason I thought it would at least load the default view by just using extends.</s></p> <p>That wasn't the correct solution although it did get it to render. It wasn't rendering correctly even though I didn't realize it at the time. The solution part is pretty verbose, because I'm hoping it will save someone else the hours I went through trying to figure out my problem.</p> <p>The correct solution was to make a class that overrides the changelist_view method then have the admin model inherit from that class. The changelist_view method is basically a copy and paste from the original changelist_view method.</p> <p>Remove the pattern in the urls.py file so it went from looking like</p> <pre><code>urlpatterns = patterns('', # Examples: url(r'^home/bam$', 'fblmanager.views.home.bam', name='bam'), url(r'^admin/comments/commenttitle/$', 'comments.admin_views.comments', name='comments'), # url(r'^emailinterface/', include('emailinterface.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), (r'^grappelli/', include('grappelli.urls')),) </code></pre> <p>to looking like</p> <pre><code>urlpatterns = patterns('', # Examples: url(r'^home/bam$', 'fblmanager.views.home.bam', name='bam'), # url(r'^emailinterface/', include('emailinterface.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), (r'^grappelli/', include('grappelli.urls')),) </code></pre> <p>then in the models.py file </p> <pre><code>class CommentTitleChangeView(admin.ModelAdmin): def changelist_view(self, request, extra_context=None): """ The 'change list' admin view for this model. """ from django.contrib.admin.views.main import ERROR_FLAG opts = self.model._meta app_label = opts.app_label if not self.has_change_permission(request, None): raise PermissionDenied list_display = self.get_list_display(request) list_display_links = self.get_list_display_links(request, list_display) # Check actions to see if any are available on this changelist actions = self.get_actions(request) if actions: # Add the action checkboxes if there are any actions available. list_display = ['action_checkbox'] + list(list_display) ChangeList = self.get_changelist(request) try: cl = ChangeList(request, self.model, list_display, list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_max_show_all, self.list_editable, self) except IncorrectLookupParameters: # Wacky lookup parameters were given, so redirect to the main # changelist page, without parameters, and pass an 'invalid=1' # parameter via the query string. If wacky parameters were given # and the 'invalid=1' parameter was already in the query string, # something is screwed up with the database, so display an error # page. if ERROR_FLAG in request.GET.keys(): return SimpleTemplateResponse('admin/invalid_setup.html', { 'title': _('Database error'), }) return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1') # If the request was POSTed, this might be a bulk action or a bulk # edit. Try to look up an action or confirmation first, but if this # isn't an action the POST will fall through to the bulk edit check, # below. action_failed = False selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME) # Actions with no confirmation if (actions and request.method == 'POST' and 'index' in request.POST and '_save' not in request.POST): if selected: response = self.response_action(request, queryset=cl.get_query_set(request)) if response: return response else: action_failed = True else: msg = _("Items must be selected in order to perform " "actions on them. No items have been changed.") self.message_user(request, msg) action_failed = True # Actions with confirmation if (actions and request.method == 'POST' and helpers.ACTION_CHECKBOX_NAME in request.POST and 'index' not in request.POST and '_save' not in request.POST): if selected: response = self.response_action(request, queryset=cl.get_query_set(request)) if response: return response else: action_failed = True # If we're allowing changelist editing, we need to construct a formset # for the changelist given all the fields to be edited. Then we'll # use the formset to validate/process POSTed data. formset = cl.formset = None # Handle POSTed bulk-edit data. if (request.method == "POST" and cl.list_editable and '_save' in request.POST and not action_failed): FormSet = self.get_changelist_formset(request) formset = cl.formset = FormSet(request.POST, request.FILES, queryset=cl.result_list) if formset.is_valid(): changecount = 0 for form in formset.forms: if form.has_changed(): obj = self.save_form(request, form, change=True) self.save_model(request, obj, form, change=True) self.save_related(request, form, formsets=[], change=True) change_msg = self.construct_change_message(request, form, None) self.log_change(request, obj, change_msg) changecount += 1 if changecount: if changecount == 1: name = force_unicode(opts.verbose_name) else: name = force_unicode(opts.verbose_name_plural) msg = ungettext("%(count)s %(name)s was changed successfully.", "%(count)s %(name)s were changed successfully.", changecount) % {'count': changecount, 'name': name, 'obj': force_unicode(obj)} self.message_user(request, msg) return HttpResponseRedirect(request.get_full_path()) # Handle GET -- construct a formset for display. elif cl.list_editable: FormSet = self.get_changelist_formset(request) formset = cl.formset = FormSet(queryset=cl.result_list) # Build the list of media to be used by the formset. if formset: media = self.media + formset.media else: media = self.media # Build the action form and populate it with available actions. if actions: action_form = self.action_form(auto_id=None) action_form.fields['action'].choices = self.get_action_choices(request) else: action_form = None selection_note_all = ungettext('%(total_count)s selected', 'All %(total_count)s selected', cl.result_count) context = { 'module_name': force_unicode(opts.verbose_name_plural), 'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, 'selection_note_all': selection_note_all % {'total_count': cl.result_count}, 'title': cl.title, 'is_popup': cl.is_popup, 'cl': cl, 'media': media, 'has_add_permission': self.has_add_permission(request), 'app_label': app_label, 'action_form': action_form, 'actions_on_top': self.actions_on_top, 'actions_on_bottom': self.actions_on_bottom, 'actions_selection_counter': self.actions_selection_counter, } context.update(extra_context or {}) return TemplateResponse(request, [ 'comments/templates/change_list.html', '/var/www/laughing-ninja/emailinterface/comments/templates/comment_list.html', 'admin/%s/change_list.html' % app_label, 'templates/change_list.html', #'admin/change_list.html' ], context, current_app=self.admin_site.name) </code></pre> <p>and the admin method</p> <pre><code>class CommentTitleAdmin(CommentTitleChangeView): list_display = ('title', ) class Meta: app_label = 'comments' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload