<?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: Extending the Django User model with inheritance</title>
	<atom:link href="http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/feed/" rel="self" type="application/rss+xml" />
	<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/</link>
	<description>Code and comments on web development, Django, Python and things (un)related.</description>
	<lastBuildDate>Wed, 16 May 2012 20:44:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dylan</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1113</link>
		<dc:creator>Dylan</dc:creator>
		<pubDate>Wed, 16 May 2012 20:44:26 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1113</guid>
		<description>I have a solution for those of you who have not been able to create super users with manage.py (either through syncdb or createsuperuser):

Add this near your CustomUser class in models.py:
&lt;pre&gt;def create_custom_user(sender, instance, created, **kwargs):
	if created:
		new_user = CustomUser(user_ptr_id=instance.id)
		new_user.__dict__.update(instance.__dict__)
		new_user.save()
post_save.connect(create_custom_user, sender=User)
&lt;/pre&gt;
Whenever a user is created it will also create an entry in the CustomUser table of the database.</description>
		<content:encoded><![CDATA[<p>I have a solution for those of you who have not been able to create super users with manage.py (either through syncdb or createsuperuser):</p>
<p>Add this near your CustomUser class in models.py:</p>
<pre>def create_custom_user(sender, instance, created, **kwargs):
	if created:
		new_user = CustomUser(user_ptr_id=instance.id)
		new_user.__dict__.update(instance.__dict__)
		new_user.save()
post_save.connect(create_custom_user, sender=User)
</pre>
<p>Whenever a user is created it will also create an entry in the CustomUser table of the database.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1106</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Wed, 28 Mar 2012 05:19:05 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1106</guid>
		<description>So, old post, but I found it so this might be helpful for someone. Similar to #74, but if you are saving your Profile outside of the admin you can override your CustomUser&#039;s save class. It could look something like this:

&lt;pre&gt;
def save(self, *args, **kwargs):
    self.set_password(self.password)
    super(CustomUser, self).save(*args, **kwargs)
&lt;/pre&gt;
https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods</description>
		<content:encoded><![CDATA[<p>So, old post, but I found it so this might be helpful for someone. Similar to #74, but if you are saving your Profile outside of the admin you can override your CustomUser&#8217;s save class. It could look something like this:</p>
<pre>
def save(self, *args, **kwargs):
    self.set_password(self.password)
    super(CustomUser, self).save(*args, **kwargs)
</pre>
<p><a href="https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mwai</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1084</link>
		<dc:creator>Mwai</dc:creator>
		<pubDate>Mon, 16 Jan 2012 19:22:08 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1084</guid>
		<description>i get this error when i try to access my version of &#039;CustomUser&#039; model on the admin site(i have shortened it for clarity):
no such column: app_name_publicprofile.user_ptr_id.
Here is my model:
&lt;pre&gt;
class PublicProfile(User):
    sex = models.CharField(max_length=100,choices=settings.SEX_CHOICES,
verbose_name=&#039;sex&#039;)
    phone_num = models.IntegerField(verbose_name=&#039;phone number&#039;)
    id_num = models.IntegerField(verbose_name=&#039;id number&#039;)
    age = models.DateField(verbose_name=&#039;date of birth&#039;)
    occupation = models.CharField(max_length= 20,
verbose_name=&#039;occupation&#039;)
    picture = models.ImageField(upload_to =&#039;user_profile_images&#039;,
verbose_name=&#039;user photo&#039;)

    objects = UserManager()
&lt;/pre&gt;
but i can add users in the admin site.

Any ideas?</description>
		<content:encoded><![CDATA[<p>i get this error when i try to access my version of &#8216;CustomUser&#8217; model on the admin site(i have shortened it for clarity):<br />
no such column: app_name_publicprofile.user_ptr_id.<br />
Here is my model:</p>
<pre>
class PublicProfile(User):
    sex = models.CharField(max_length=100,choices=settings.SEX_CHOICES,
verbose_name='sex')
    phone_num = models.IntegerField(verbose_name='phone number')
    id_num = models.IntegerField(verbose_name='id number')
    age = models.DateField(verbose_name='date of birth')
    occupation = models.CharField(max_length= 20,
verbose_name='occupation')
    picture = models.ImageField(upload_to ='user_profile_images',
verbose_name='user photo')

    objects = UserManager()
</pre>
<p>but i can add users in the admin site.</p>
<p>Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mghs</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1071</link>
		<dc:creator>mghs</dc:creator>
		<pubDate>Fri, 30 Dec 2011 09:30:31 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1071</guid>
		<description>Hi Scott, liked the inheritance but can anyone suggest how I can make an attribute of the child model required, if it is inheriting the User class without saving the user if the instance of the child model is not saved? eg.

&lt;pre&gt;class Customer(User):
organization = models.CharField(max_length=80, unique = True)
address = models.CharField(max_length=80)
.
..
objects = UserManager()&lt;/pre&gt;
 
If in the admin.py, model Customer is registered, on execution, we get the user creation form, with password after saving it, we exit from the module. We are able to see that the user exists in the django Auth, even if the Customer is not yet created. How do I override the save of the User class. Also I need to create other users for the application the normal way. Please suggest</description>
		<content:encoded><![CDATA[<p>Hi Scott, liked the inheritance but can anyone suggest how I can make an attribute of the child model required, if it is inheriting the User class without saving the user if the instance of the child model is not saved? eg.</p>
<pre>class Customer(User):
organization = models.CharField(max_length=80, unique = True)
address = models.CharField(max_length=80)
.
..
objects = UserManager()</pre>
<p>If in the admin.py, model Customer is registered, on execution, we get the user creation form, with password after saving it, we exit from the module. We are able to see that the user exists in the django Auth, even if the Customer is not yet created. How do I override the save of the User class. Also I need to create other users for the application the normal way. Please suggest</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Django con Admin MultiSite &#171; developer.cl</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1061</link>
		<dc:creator>Django con Admin MultiSite &#171; developer.cl</dc:creator>
		<pubDate>Mon, 26 Sep 2011 04:04:06 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1061</guid>
		<description>[...] referencia y tienen algunos de estos ejemplos: Documentación en DJango para múltiples sitios  Extending the django user model with inheritance Doing more with the Django admin Add a button to Django admin to login as a user   [...]</description>
		<content:encoded><![CDATA[<p>[...] referencia y tienen algunos de estos ejemplos: Documentación en DJango para múltiples sitios  Extending the django user model with inheritance Doing more with the Django admin Add a button to Django admin to login as a user   [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Come estendere la classe User in Django</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1054</link>
		<dc:creator>Come estendere la classe User in Django</dc:creator>
		<pubDate>Tue, 09 Aug 2011 15:22:43 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1054</guid>
		<description>[...] codice l&#8217;ho rubacchiato da un blog. from django.contrib.auth.models import User, UserManager  class CustomUser&#40;User&#41;: &#160; [...]</description>
		<content:encoded><![CDATA[<p>[...] codice l&#8217;ho rubacchiato da un blog. from django.contrib.auth.models import User, UserManager  class CustomUser&#40;User&#41;: &nbsp; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mark</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1052</link>
		<dc:creator>mark</dc:creator>
		<pubDate>Fri, 29 Jul 2011 10:30:01 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1052</guid>
		<description>Ammara - see this post for a variation that deals with the Pasword not being encrypted and also the admin user not using this class but instead the original User.
http://www.kolios.dk/2010/01/22/how-to-extend-django-user-class-and-change-authentication-middleware/
Also see here for a more elegant solution for User override using User classname instead of CustomUser and Admin fix.
http://nigel.jp/2011/06/django-user-authentication-and-extending-the-user-model/

However you need to mix all three approaches to solve the problems in any one of them.
Would be great if this post was updated (or a new post replacing it) to reflect the best way to do all of this... (IMHO)
Thanks Scott for getting this started... Please consider doing an update and straighteneing all the wiggles out...</description>
		<content:encoded><![CDATA[<p>Ammara &#8211; see this post for a variation that deals with the Pasword not being encrypted and also the admin user not using this class but instead the original User.<br />
<a href="http://www.kolios.dk/2010/01/22/how-to-extend-django-user-class-and-change-authentication-middleware/" rel="nofollow">http://www.kolios.dk/2010/01/22/how-to-extend-django-user-class-and-change-authentication-middleware/</a><br />
Also see here for a more elegant solution for User override using User classname instead of CustomUser and Admin fix.<br />
<a href="http://nigel.jp/2011/06/django-user-authentication-and-extending-the-user-model/" rel="nofollow">http://nigel.jp/2011/06/django-user-authentication-and-extending-the-user-model/</a></p>
<p>However you need to mix all three approaches to solve the problems in any one of them.<br />
Would be great if this post was updated (or a new post replacing it) to reflect the best way to do all of this&#8230; (IMHO)<br />
Thanks Scott for getting this started&#8230; Please consider doing an update and straighteneing all the wiggles out&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ammara</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1051</link>
		<dc:creator>Ammara</dc:creator>
		<pubDate>Mon, 18 Jul 2011 02:20:42 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1051</guid>
		<description>I have used the inheritence method to build a CustomUser class. Apparently its working absolutely fine but when I create a new user from admin, its password is not being encoded and as a result, I am unable to login with the newly created user. However, login action do not produce any error on the screen but the user is not being redirected to its home page. When I try to update the user from admin site. the password is being displayed in plain text and not in the encded format.

thanks in advance for any help. I am really stuck!!!</description>
		<content:encoded><![CDATA[<p>I have used the inheritence method to build a CustomUser class. Apparently its working absolutely fine but when I create a new user from admin, its password is not being encoded and as a result, I am unable to login with the newly created user. However, login action do not produce any error on the screen but the user is not being redirected to its home page. When I try to update the user from admin site. the password is being displayed in plain text and not in the encded format.</p>
<p>thanks in advance for any help. I am really stuck!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Extending the User model with custom fields in Django - Programmers Goodies</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1049</link>
		<dc:creator>Extending the User model with custom fields in Django - Programmers Goodies</dc:creator>
		<pubDate>Mon, 04 Jul 2011 17:46:06 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1049</guid>
		<description>[...] already seen a few ways to do it, but can&#8217;t decide on which one is the [...]</description>
		<content:encoded><![CDATA[<p>[...] already seen a few ways to do it, but can&#8217;t decide on which one is the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Extendendo User do Django &#171; Fred Chevitarese &#8230;</title>
		<link>http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/comment-page-2/#comment-1048</link>
		<dc:creator>Extendendo User do Django &#171; Fred Chevitarese &#8230;</dc:creator>
		<pubDate>Tue, 28 Jun 2011 13:31:13 +0000</pubDate>
		<guid isPermaLink="false">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/#comment-1048</guid>
		<description>[...] Outro artigo muito bom (inglês) é este aqui. http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance [...]</description>
		<content:encoded><![CDATA[<p>[...] Outro artigo muito bom (inglês) é este aqui. <a href="http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance" rel="nofollow">http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance</a> [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.236 seconds -->

