Skip to content

Commit

Permalink
Added Profile model one-to-one with User
Browse files Browse the repository at this point in the history
  • Loading branch information
SaxonDouglass committed Dec 4, 2013
1 parent f5d4e74 commit 41ee7b0
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 23 deletions.
16 changes: 16 additions & 0 deletions accounts/admin.py
@@ -0,0 +1,16 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from accounts.models import Profile

class ProfileInline(admin.TabularInline):
model = Profile
can_delete = False
verbose_name_plural = 'profile'

class UserAdmin(admin.ModelAdmin):
inlines = (ProfileInline, )

admin.site.unregister(User)
admin.site.register(User, UserAdmin)
21 changes: 21 additions & 0 deletions accounts/models.py
@@ -0,0 +1,21 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver

class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL)
bio = models.TextField(blank=True)
def __unicode__(self):
return self.user.get_full_name()

# Signal handlers
@receiver(post_save, sender=User)
def user_post_save_callback(sender, **kwargs):
created = kwargs['created']
instance = kwargs['instance']
if created:
profile = Profile();
profile.user = instance
profile.save()
10 changes: 5 additions & 5 deletions accounts/urls.py
Expand Up @@ -3,9 +3,9 @@
from accounts.views import *

urlpatterns = patterns('',
url(r'^profile/?$', profile, {}, "accounts-profile"),
(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'accounts/login.html'}, "accounts-login"),
(r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'accounts/logout.html'}, "accounts-logout"),
(r'^change-password/$', 'django.contrib.auth.views.password_change', {'template_name': 'accounts/password-change.html'}, "accounts-password-change"),
(r'^password-changed/$', 'django.contrib.auth.views.password_change_done', {'template_name': 'accounts/password-change-done.html'}, "accounts-password-change-done"),
url(r'^profile/?$', profile, {}, "profile"),
(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'accounts/login.html'}, "login"),
(r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'accounts/logout.html'}, "logout"),
(r'^password-change/$', 'django.contrib.auth.views.password_change', {'template_name': 'accounts/password-change.html'}, "password_change"),
(r'^password-change-done/$', 'django.contrib.auth.views.password_change_done', {'template_name': 'accounts/password-change-done.html'}, "password_change_done"),
)
4 changes: 2 additions & 2 deletions jamalaide/urls.py
Expand Up @@ -5,14 +5,14 @@
admin.autodiscover()

urlpatterns = patterns('',
url(r'^$', include('news.urls')),
url(r'^accounts/', include('accounts.urls')),
url(r'^jams/', include('jams.urls')),
url(r'^games/?$', 'jams.views.games'),
url(r'^admin/', include(admin.site.urls)),
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
url(r'^$', include('news.urls')),
url(r'^accounts/', include('accounts.urls')),
)

# Flatpages
Expand Down
11 changes: 0 additions & 11 deletions templates/about.html

This file was deleted.

2 changes: 1 addition & 1 deletion templates/accounts/login.html
Expand Up @@ -4,7 +4,7 @@

{{ form.non_field_errors }}

<form method="post" action="{% url accounts-login %}">
<form method="post" action="{% url 'login' %}">
{% csrf_token %}

<div class="left">{{ form.username.label_tag }}</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/accounts/profile.html
Expand Up @@ -4,6 +4,6 @@

<h1>Profile</h1>

Would you like to <a href="/accounts/change-password">change your password</a>?
Would you like to <a href="{% url 'password_change' %}">change your password</a>?

{% endblock %}
6 changes: 3 additions & 3 deletions templates/base.html
Expand Up @@ -14,10 +14,10 @@
<div id="account">
{% if user.is_authenticated %}
<p>Welcome, {{ user.username }}.<br>
<a href="{% url 'accounts-profile' %}">Profile</a> -
<a href="{% url 'accounts-logout' %}">Logout</a></p>
<a href="{% url 'profile' %}">Profile</a> -
<a href="{% url 'logout' %}">Logout</a></p>
{% else %}
<p><a href="{% url 'accounts-login' %}">Login</a></p>
<p><a href="{% url 'login' %}">Login</a></p>
{% endif %}
</div>
</header>
Expand Down

0 comments on commit 41ee7b0

Please sign in to comment.