Issue
I'm tearing my hair out trying to figure out why my custom user profile view no longer works. I'm using django-allauth, and have customised my user profile by creating a model with one-to-one field to the user. However, my view is throwing the error:
OperationalError at /profile/
no such table: user_profile
Request Method: GET
Request URL: http://localhost:8000/profile/
Django Version: 1.7.4
Exception Type: OperationalError
Exception Value:
no such table: user_profile
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py in execute, line 485
Python Executable: /usr/bin/python
Python Version: 2.7.6
My models.py with the custom user profile looks like this:
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.db import models
from allauth.account.models import EmailAddress
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='profile')
# user visible settings
stop_reminders = models.BooleanField ( default=False,
help_text = 'Flag if user wants reminders not to be sent.' )
stop_all_email = models.BooleanField ( default=False,
help_text = 'Flag if user wants no email to be sent.' )
# hidden settings
is_premium = models.BooleanField ( default=False,
help_text = 'Flag if user has the premium service.' )
def __unicode__(self):
return "{}'s profile".format(self.user.username)
class Meta:
db_table = 'user_profile'
def account_verified(self):
if self.user.is_authenticated:
result = EmailAddress.objects.filter(email=self.user.email)
if len(result):
return result[0].verified
return False
#User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
def create_user_profile(sender, instance, created, **kwargs):
if created:
profile, created = UserProfile.objects.get_or_create(user=instance)
post_save.connect(create_user_profile, sender=User)
My view, which is a place to set user profile settings looks like this:
@login_required
def user_settings (request):
"""
User settings view, handles changing of user settings and
entry distribution (eventually)
"""
if request.method == 'POST': # If the form has been submitted...
form = UserProfileForm(request.POST, instance=request.user.profile) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
form.save ()
return render_to_response('sm/profile_update_success.html',
{},
context_instance=RequestContext(request))
else:
# create unbound form with initial values generated
# from the user's profile
form = UserProfileForm (instance=request.user.profile)
return render ( request, 'profile.html', { 'form': form, } )
Until recently this was working fine, and I'm not sure what has changed to make it stop. Can anyone explain please?
I'm using Django-1.7.4 and django-allauth-0.19.1. For debug I'm using sqllite, which I have tried creating using both python manage.py migrate
and python manage.py syncdb
.
Solution
Gahh, the answer was that I had commented out my main app's entry from INSTALLED_APPS
. Which is silly.
Answered By - crobar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.