<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" > <channel><title>Comments on: A Detailed Django Tutorial: Blog Basics Part II</title> <atom:link href="http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/feed/" rel="self" type="application/rss+xml" /><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/</link> <description>a winnipeg website design company.</description> <lastBuildDate>Thu, 09 Feb 2012 06:42:48 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>By: Peter Hanley</title><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/comment-page-1/#comment-26970</link> <dc:creator>Peter Hanley</dc:creator> <pubDate>Mon, 02 Aug 2010 14:11:51 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=821#comment-26970</guid> <description>My previous comment had an error - changing the code to &quot;obj.author = request.author&quot; will generate another error.However, changing the placement of the save_model code block to right underneath the class definition fixes the problem (not sure why, but I&#039;m assuming it&#039;s to do with when the different lines actually execute): &lt;code&gt; from django.contrib import admin from models import Post class PostAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): if not change: obj.author = request.user obj.save() fields = (  &#039;title&#039; , &#039;body&#039;) list_display = (&#039;title&#039;, &#039;author&#039;, &#039;pub_date&#039;) date_hierarchy = &#039;pub_date&#039; admin.site.register(Post, PostAdmin) &lt;/code&gt; Note that if you copy/paste this block, you may have to clean up your indentation.</description> <content:encoded><![CDATA[<p>My previous comment had an error &#8211; changing the code to &#8220;obj.author = request.author&#8221; will generate another error.</p><p>However, changing the placement of the save_model code block to right underneath the class definition fixes the problem (not sure why, but I&#8217;m assuming it&#8217;s to do with when the different lines actually execute):<br /> <code><br /> from django.contrib import admin<br /> from models import Post<br /> class PostAdmin(admin.ModelAdmin):<br /> def save_model(self, request, obj, form, change):<br /> if not change:<br /> obj.author = request.user<br /> obj.save()<br /> fields = (  'title' , 'body')<br /> list_display = ('title', 'author', 'pub_date')<br /> date_hierarchy = 'pub_date'<br /> admin.site.register(Post, PostAdmin)<br /> </code><br /> Note that if you copy/paste this block, you may have to clean up your indentation.</p> ]]></content:encoded> </item> <item><title>By: Peter Hanley</title><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/comment-page-1/#comment-26968</link> <dc:creator>Peter Hanley</dc:creator> <pubDate>Mon, 02 Aug 2010 14:01:01 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=821#comment-26968</guid> <description>Unfortunately, adding author to the fields - while it does make the page work - also undoes what he was showing users how to do (adding the current logged in user as a hidden, unchangeable value rather than a selectable list)I looked up the related documentation and foundclass ArticleAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): obj.user = request.user obj.save()at http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_modelI had hoped that obj.author = request.user was a typo and tried changing the line to obj.author = request.author on the grounds that there wasn&#039;t a user defined explicitly in the app, but it also didn&#039;t work.  :(I&#039;m still looking around, though.</description> <content:encoded><![CDATA[<p>Unfortunately, adding author to the fields &#8211; while it does make the page work &#8211; also undoes what he was showing users how to do (adding the current logged in user as a hidden, unchangeable value rather than a selectable list)</p><p>I looked up the related documentation and found</p><p>class ArticleAdmin(admin.ModelAdmin):<br /> def save_model(self, request, obj, form, change):<br /> obj.user = request.user<br /> obj.save()</p><p>at <a href="http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model" rel="nofollow">http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model</a></p><p>I had hoped that obj.author = request.user was a typo and tried changing the line to<br /> obj.author = request.author<br /> on the grounds that there wasn&#8217;t a user defined explicitly in the app, but it also didn&#8217;t work. <img src='http://brenelz.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /></p><p>I&#8217;m still looking around, though.</p> ]]></content:encoded> </item> <item><title>By: Joey</title><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/comment-page-1/#comment-19863</link> <dc:creator>Joey</dc:creator> <pubDate>Fri, 18 Jun 2010 07:42:26 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=821#comment-19863</guid> <description>admin.py-- from django.contrib import admin from models import Postclass PostAdmin(admin.ModelAdmin): fields = (&#039;author&#039;, &#039;title&#039;, &#039;body&#039;) list_display = (&#039;title&#039;, &#039;author&#039;, &#039;pub_date&#039;) date_hierarchy = &#039;pub_date&#039; def save_model(self, request, obj, form, change): if not change: obj.author = request.user obj.save() admin.site.register(Post, PostAdmin)--You have to add author to fields.</description> <content:encoded><![CDATA[<p>admin.py</p><p>&#8211;<br /> from django.contrib import admin<br /> from models import Post</p><p>class PostAdmin(admin.ModelAdmin):<br /> fields = (&#8216;author&#8217;, &#8216;title&#8217;, &#8216;body&#8217;)<br /> list_display = (&#8216;title&#8217;, &#8216;author&#8217;, &#8216;pub_date&#8217;)<br /> date_hierarchy = &#8216;pub_date&#8217;<br /> def save_model(self, request, obj, form, change):<br /> if not change:<br /> obj.author = request.user<br /> obj.save()<br /> admin.site.register(Post, PostAdmin)</p><p>&#8211;</p><p>You have to add author to fields.</p> ]]></content:encoded> </item> <item><title>By: Error in Section 1</title><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/comment-page-1/#comment-10906</link> <dc:creator>Error in Section 1</dc:creator> <pubDate>Sun, 21 Mar 2010 22:58:42 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=821#comment-10906</guid> <description>In section 1 there was a typing error for creating the posts app: you said to put &quot;python manage.py startproject posts&quot;, when it should have been &quot;python manage.py startapp posts&quot;. Luckily, I caught the error before I tried to run your code.</description> <content:encoded><![CDATA[<p>In section 1 there was a typing error for creating the posts app: you said to put &#8220;python manage.py startproject posts&#8221;, when it should have been &#8220;python manage.py startapp posts&#8221;. Luckily, I caught the error before I tried to run your code.</p> ]]></content:encoded> </item> <item><title>By: lizzie</title><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/comment-page-1/#comment-1012</link> <dc:creator>lizzie</dc:creator> <pubDate>Thu, 08 Oct 2009 17:31:57 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=821#comment-1012</guid> <description>I have the same error as Jack, here&#039;s the traceback: Traceback: File &quot;/var/lib/python-support/python2.6/django/core/handlers/base.py&quot; in get_response 86.                 response = callback(request, *callback_args, **callback_kwargs) File &quot;/var/lib/python-support/python2.6/django/contrib/admin/sites.py&quot; in root 157.                 return self.model_page(request, *url.split(&#039;/&#039;, 2)) File &quot;/var/lib/python-support/python2.6/django/views/decorators/cache.py&quot; in _wrapped_view_func 44.         response = view_func(request, *args, **kwargs) File &quot;/var/lib/python-support/python2.6/django/contrib/admin/sites.py&quot; in model_page 176.         return admin_obj(request, rest_of_url) File &quot;/var/lib/python-support/python2.6/django/contrib/admin/options.py&quot; in __call__ 191.             return self.add_view(request) File &quot;/var/lib/python-support/python2.6/django/db/transaction.py&quot; in _commit_on_success 238.                 res = func(*args, **kw) File &quot;/var/lib/python-support/python2.6/django/contrib/admin/options.py&quot; in add_view 494.                 self.save_model(request, new_object, form, change=False) File &quot;/var/lib/python-support/python2.6/django/contrib/admin/options.py&quot; in save_model 376.         obj.save() File &quot;/var/lib/python-support/python2.6/django/db/models/base.py&quot; in save 311.         self.save_base(force_insert=force_insert, force_update=force_update) File &quot;/var/lib/python-support/python2.6/django/db/models/base.py&quot; in save_base 383.                 result = manager._insert(values, return_id=update_pk) File &quot;/var/lib/python-support/python2.6/django/db/models/manager.py&quot; in _insert 138.         return insert_query(self.model, values, **kwargs) File &quot;/var/lib/python-support/python2.6/django/db/models/query.py&quot; in insert_query 894.     return query.execute_sql(return_id) File &quot;/var/lib/python-support/python2.6/django/db/models/sql/subqueries.py&quot; in execute_sql 309.         cursor = super(InsertQuery, self).execute_sql(None) File &quot;/var/lib/python-support/python2.6/django/db/models/sql/query.py&quot; in execute_sql 1734.         cursor.execute(sql, params) File &quot;/var/lib/python-support/python2.6/django/db/backends/util.py&quot; in execute 19.             return self.cursor.execute(sql, params) File &quot;/var/lib/python-support/python2.6/django/db/backends/sqlite3/base.py&quot; in execute 168.         return Database.Cursor.execute(self, query, params)Exception Type: IntegrityError at /admin/posts/post/add/ Exception Value: posts_post.author_id may not be NULLAny suggestions?</description> <content:encoded><![CDATA[<p>I have the same error as Jack, here&#8217;s the traceback:<br /> Traceback:<br /> File &#8220;/var/lib/python-support/python2.6/django/core/handlers/base.py&#8221; in get_response<br /> 86.                 response = callback(request, *callback_args, **callback_kwargs)<br /> File &#8220;/var/lib/python-support/python2.6/django/contrib/admin/sites.py&#8221; in root<br /> 157.                 return self.model_page(request, *url.split(&#8216;/&#8217;, 2))<br /> File &#8220;/var/lib/python-support/python2.6/django/views/decorators/cache.py&#8221; in _wrapped_view_func<br /> 44.         response = view_func(request, *args, **kwargs)<br /> File &#8220;/var/lib/python-support/python2.6/django/contrib/admin/sites.py&#8221; in model_page<br /> 176.         return admin_obj(request, rest_of_url)<br /> File &#8220;/var/lib/python-support/python2.6/django/contrib/admin/options.py&#8221; in __call__<br /> 191.             return self.add_view(request)<br /> File &#8220;/var/lib/python-support/python2.6/django/db/transaction.py&#8221; in _commit_on_success<br /> 238.                 res = func(*args, **kw)<br /> File &#8220;/var/lib/python-support/python2.6/django/contrib/admin/options.py&#8221; in add_view<br /> 494.                 self.save_model(request, new_object, form, change=False)<br /> File &#8220;/var/lib/python-support/python2.6/django/contrib/admin/options.py&#8221; in save_model<br /> 376.         obj.save()<br /> File &#8220;/var/lib/python-support/python2.6/django/db/models/base.py&#8221; in save<br /> 311.         self.save_base(force_insert=force_insert, force_update=force_update)<br /> File &#8220;/var/lib/python-support/python2.6/django/db/models/base.py&#8221; in save_base<br /> 383.                 result = manager._insert(values, return_id=update_pk)<br /> File &#8220;/var/lib/python-support/python2.6/django/db/models/manager.py&#8221; in _insert<br /> 138.         return insert_query(self.model, values, **kwargs)<br /> File &#8220;/var/lib/python-support/python2.6/django/db/models/query.py&#8221; in insert_query<br /> 894.     return query.execute_sql(return_id)<br /> File &#8220;/var/lib/python-support/python2.6/django/db/models/sql/subqueries.py&#8221; in execute_sql<br /> 309.         cursor = super(InsertQuery, self).execute_sql(None)<br /> File &#8220;/var/lib/python-support/python2.6/django/db/models/sql/query.py&#8221; in execute_sql<br /> 1734.         cursor.execute(sql, params)<br /> File &#8220;/var/lib/python-support/python2.6/django/db/backends/util.py&#8221; in execute<br /> 19.             return self.cursor.execute(sql, params)<br /> File &#8220;/var/lib/python-support/python2.6/django/db/backends/sqlite3/base.py&#8221; in execute<br /> 168.         return Database.Cursor.execute(self, query, params)</p><p>Exception Type: IntegrityError at /admin/posts/post/add/<br /> Exception Value: posts_post.author_id may not be NULL</p><p>Any suggestions?</p> ]]></content:encoded> </item> <item><title>By: Jack</title><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/comment-page-1/#comment-1011</link> <dc:creator>Jack</dc:creator> <pubDate>Sat, 05 Sep 2009 11:50:11 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=821#comment-1011</guid> <description>I get the following error when I try to save a post:IntegrityError at /admin/posts/post/add/posts_post.author_id may not be NULLAny idea what could be causing that?</description> <content:encoded><![CDATA[<p>I get the following error when I try to save a post:</p><p>IntegrityError at /admin/posts/post/add/</p><p>posts_post.author_id may not be NULL</p><p>Any idea what could be causing that?</p> ]]></content:encoded> </item> <item><title>By: Jeff</title><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/comment-page-1/#comment-1010</link> <dc:creator>Jeff</dc:creator> <pubDate>Sun, 14 Jun 2009 22:24:27 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=821#comment-1010</guid> <description>If I recall correctly, this was changed in some svn revision.Just wondering, are you using SVN or 1.0?</description> <content:encoded><![CDATA[<p>If I recall correctly, this was changed in some svn revision.</p><p>Just wondering, are you using SVN or 1.0?</p> ]]></content:encoded> </item> <item><title>By: Spy</title><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/comment-page-1/#comment-1008</link> <dc:creator>Spy</dc:creator> <pubDate>Fri, 24 Apr 2009 14:29:36 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=821#comment-1008</guid> <description>Hi,I have had a problem with urlpatterns, in my opinion instead of (r’^admin/’, include(admin.site.urls)), should be (r&#039;^admin/(.*)&#039;, admin.site.root), Regards, Spy</description> <content:encoded><![CDATA[<p>Hi,</p><p>I have had a problem with urlpatterns, in my opinion instead of<br /> (r’^admin/’, include(admin.site.urls)),<br /> should be<br /> (r&#8217;^admin/(.*)&#8217;, admin.site.root),<br /> Regards,<br /> Spy</p> ]]></content:encoded> </item> <item><title>By: Django Blog Tutorial &#124; Blog of Jeff</title><link>http://brenelz.com/blog/a-detailed-django-tutorial-blog-basics-part-ii/comment-page-1/#comment-1009</link> <dc:creator>Django Blog Tutorial &#124; Blog of Jeff</dc:creator> <pubDate>Fri, 03 Apr 2009 07:49:28 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=821#comment-1009</guid> <description>[...] Part 2 [...]</description> <content:encoded><![CDATA[<p>[...] Part 2 [...]</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 26/40 queries in 0.009 seconds using disk: basic
Object Caching 615/615 objects using disk: basic

Served from: brenelz.com @ 2012-02-10 05:37:52 -->
