0

私はDmitryチュートリアルに従って、追加のフィールドでdjango-registrationプラグインの登録を拡張しました。ユーザーは今すぐ登録できますが、追加のフィールドは保存されません。エラーが発生し続けます。

Djangoバージョン:1.4.2
例外タイプ:InternalError例外値:現在のトランザクションは中止され、トランザクションブロックが終了するまでコマンドは無視されます例外の
場所:/root/env27/lib/python2.7/site-packages/django/db/models/sql execute_sqlの/compiler.py、行910

また、postgresqlログを見ると、登録機能を実行すると次のエントリが表示されます。

required" value="serkan" name="name" />', NULL, NULL, NULL, NULL, NULL, NULL, NULL, E'') RETURNING "dirapp_userprofile"."id" 2013-03-03

12:28:45 ESTエラー:現在のトランザクションは中止され、トランザクションブロックが終了するまでコマンドは無視されます2013-03-03 12:28:45 ESTステートメント:SHOW default_transaction_isolation 2013-03-03 12:29:59 ESTエラー:キーが重複しています値が一意の制約"dirapp_userprofile_user_id_key"に違反しています2013-03-0312:29:59ESTステートメント:INSERT INTO "dirapp_userprofile"( "user_id"、 "name"、 "email"、 "phone"、 "point"、 "address"、 "city"、 "state"、 "zipcode"、 "description")VALUES(48、E'serkan'、NULL、NULL、NULL、NULL、NULL、NULL、NULL、E'')RETURNING"dirapp_userprofile"。"id "2013-03-03 12:29:59 ESTエラー:現在のトランザクションは中止されました、トランザクションブロックが終了するまでコマンドは無視されます2013-03-0312:29:59ESTステートメント:SHOW default_transaction_isolation ransaction_isolation 2013-03-03 12:29:59 ESTエラー:重複するキー値が一意の制約「dirapp_userprofile_user_id_key」に違反していますransaction_isolation 2013-03- 03 12:29:59 ESTエラー:重複キー値が一意の制約「dirapp_userprofile_user_id_key」に違反しています2013-03-03 12:36:59 ESTエラー:重複キー値が一意の制約「dirapp_userprofile_user_id_key」に違反しています2013-03-03 12:36:59 ESTステートメント:INSERT INTO "dirapp_userprofile"( "user_id"、 "name"、 "email"、 "phone"、 "point"、 "address"、 "city"、 "state"、 "zipcode"、 "description")値(49、E'serkan'、NULL、NULL、NULL、NULL、NULL、NULL、NULL、E'')RETURNING"dirapp_userprofile"。"id" 2013-03-03 12:36:59 ESTエラー:現在のトランザクションは中止され、コマンドはトランザクションが終了するまで無視されますブロック2013-03-0312:36:59ESTステートメント:SHOW default_transaction_isolation 2013-03-03 13:02:10 ESTエラー:重複するキー値が一意の制約「dirapp_userprofile_user_id_key」に違反しています2013-03-0313:02:10ESTステートメント:INSERT INTO "dirapp_userprofile"( "user_id"、 "name"、 "email"、 "phone"、 "point"、 "address"、 "city"、 "state"、 "zipcode"、 "description")VALUES(50 、E'serkan'、NULL、NULL、NULL、NULL、NULL、NULL、NULL、E'')RETURNING"dirapp_userprofile"。"id"2013-03-03 13:02:10 ESTエラー:現在のトランザクションは中止され、トランザクションブロックが終了するまでコマンドは無視されます2013-03-03 13:02:10 ESTステートメント:SHOW default_transaction_isolation 2013-03-03 13:54:51 ESTエラー:重複するキー値が一意の制約"dirapp_userprofile_user_id_key"に違反しています2013-03-0313:54:51ESTステートメント:INSERT INTO "dirapp_userprofile"( "user_id"、 "name"、 "email"、 "phone"、 "point" 、"address"、 "city"、 "state"、 "zipcode"、 "description")VALUES(51、E'serkan'、NULL、NULL、NULL、NULL、NULL、NULL、NULL、E'')RETURNING " dirapp_userprofile"。"id"2013-03-03 13:54:51 ESTエラー:現在のトランザクションは中止されました。トランザクションブロックが終了するまでコマンドは無視されます2013-03-0313:54:51ESTステートメント:SHOW default_transaction_isolation

誰かが私を正しい方向に見つけることができることを期待して、何が問題であるかを理解することはできません。

models.py

クラスUserProfile(models.Model):

user = models.ForeignKey(User, unique=True)
name = models.CharField(max_length=60, blank=True, null=True)
email = models.CharField(max_length=50,blank=True, null=True)
phone = models.CharField(max_length=20, blank=True,null=True) 
point = models.PointField(srid=settings.SRID, blank=True, null=True)
address = models.CharField(max_length=60, blank=True, null=True)
city = models.CharField(max_length=60, blank=True, null=True)
state = models.CharField(max_length=60, blank=True, null=True)
zipcode = models.CharField(max_length=5,blank=True, null=True)
description = models.TextField()

def __unicode__(self):
    return unicode(self.user)

#ベンダーボックスがチェックされているかどうかを確認します@propertydefis_vendor(self):try:self.vendor return True(Vendor.DoesNotExistを除く):return False

class UserProfileForm(ModelForm):class Meta:model = UserProfile Exclusive = ["user"、 "point"]

urls.py

from djangoratings.views import AddRatingFromModel
from registration.views import register, activate
import dirapp.regbackend
from django.views.generic.simple import direct_to_template
from dirapp.forms import UserRegistrationFormz
from registration.views import register
#import registration.backends.default.urls as regUrls
import registration.backends.default.urls as regUrls


listing_list = {"queryset":Listing.objects.all()}


urlpatterns = patterns('', 
    url(r'^$',index,name='index'),
    url(r'^accounts/register/$', register, { 'backend': 'registration.backends.default.DefaultBackend','form_class':UserRegistrationFormz}, name='registration_register'),  
    url(r'^accounts/', include(regUrls)), 
    url(r'^profile/$', user_profile, name='user-profile-view'),

regbackend.py

    from dirapp.forms import UserRegistrationFormz
    from dirapp.models import UserProfile
    from django import forms

    def user_created(sender, user, request, **kwargs):
        form = UserRegistrationFormz(request.POST)
        data = UserProfile(user=user)
        data.name = form.data['name']
        data.save()

    from registration.signals import user_registered
    user_registered.connect(user_created)

forms.py

from django.contrib.gis import forms
from django.contrib.auth.models import User
from django.db.models import Q
from dirapp.models import UserProfile
from django import forms
from registration.forms import RegistrationForm, RegistrationFormTermsOfService
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from registration.models import RegistrationProfile
from forms import *
from django import forms

#class ProfileForm(forms.Form):
#    name = forms.CharField()

#    def save(self,user):
#        try:
#            data = user.get_profile()
#        except:
#            data = UserProfile(user=user)
#        data.name = self.cleaned["name"]
#        data.save()



attrs_dict = {'class':'required'}

class UserRegistrationFormz(RegistrationForm):
    name = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))

トレースバック

Environment:


Request Method: POST
Request URL: http://localhost:8000/accounts/register/

Django Version: 1.4.2
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.humanize',
 'django.contrib.gis',
 'django.contrib.staticfiles',
 'south',
 'dirapp',
 'registration',
 'django_extensions',
 'sorl.thumbnail',
 'debug_toolbar',
 'taggit',
 'djangoratings')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware')


Traceback:
File "/root/env27/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/root/posguide/../posguide/registration/views.py" in register
  187.             new_user = backend.register(request, **form.cleaned_data)
File "/root/posguide/registration/backends/default/__init__.py" in register
  82.                                      request=request)
File "/root/env27/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
  172.             response = receiver(signal=self, sender=sender, **named)
File "/root/posguide/../posguide/dirapp/regbackend.py" in user_created
  9.     data.save()
File "/root/env27/lib/python2.7/site-packages/django/db/models/base.py" in save
  463.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/root/env27/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  551.                 result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/root/env27/lib/python2.7/site-packages/django/db/models/manager.py" in _insert
  203.         return insert_query(self.model, objs, fields, **kwargs)
File "/root/env27/lib/python2.7/site-packages/django/db/models/query.py" in insert_query
  1593.     return query.get_compiler(using=using).execute_sql(return_id)
File "/root/env27/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  910.             cursor.execute(sql, params)

Exception Type: InternalError at /accounts/register/
Exception Value: current transaction is aborted, commands ignored until end of transaction block
4

1 に答える 1

0

解決するのは簡単だったことがわかりました。regbackendpyのinqueryを少し変更すると、機能するようになりました。

from dirapp.forms import UserRegistrationFormz
    from dirapp.models import UserProfile
    from django import forms

    def user_created(sender, user, request, **kwargs):
        form = UserRegistrationFormz(request.POST)
        **data = UserProfile.objects.get(user=user.id)**
        data.name = form.data['name']
        data.save()

    from registration.signals import user_registered
    user_registered.connect(user_created)
于 2013-03-04T02:00:24.893 に答える