几个小时以来,我一直在努力查看这段代码有什么问题。我正在处理的项目呼吁用户注册到站点(由Django 注册插件处理。)一旦注册,用户将能够将他们的公司(姓名、地址、电话等)添加到站点作为清单。所以公司有自己的模式。我正在使用 Django 个人资料在 Django 个人资料页面上显示用户信息和公司信息。Profiles 也建立在Django Profiles 插件之上。
url(r'^accounts/', include('registration.urls')),
url(r'^admin_export/', include("admin_export.urls")),
url(r'^profiles/edit', 'profiles.views.edit_profile'),
url(r'^profiles/create', 'profiles.views.create_profile'),
url(r'^profiles/', include('profiles.urls')),
url(r'^profiles/(?P<username>\w+)/$', 'profiles.views.profile_detail',name='UserProfileView'),
url(r'^comments/', include('django.contrib.comments.urls'))
#models.py
class UserProfile(models.Model):
user = models.ForeignKey(User,unique=True)
#email = models.CharField(max_length=200, blank=True, null=True)
# Other fields here
#company = models.ForeignKey(Company,blank=True,null=True)
#office = models.CharField(max_length=200, blank=True, null=True)
def __unicode__(self):
return self.user.username
class Company(models.Model):
userprofile = models.ForeignKey(UserProfile, null=True, blank=True)
comp_name = models.CharField(max_length=200,blank=True,null=True)
comp_address = models.CharField(max_length=200,blank=True, null=True)
comp_email = models.CharField(max_length=200,blank=True, null=True)
comp_zip = models.IntegerField(blank=True, null=True)
comp_phone = models.IntegerField(blank=True, null=True)
comp_city = models.CharField(max_length=200,blank=True, null=True)
#comp_state = models.USStateField(blank=True, null=True
comp_state = models.CharField(blank=True, max_length=2)
compwebsite = models.URLField(max_length=200, blank=True, null=True)
twitterurl = models.URLField(max_length=200, blank=True, null=True)
facebookurl = models.URLField(max_length=200, blank=True, null=True)
def __unicode__(self):
return self.comp_name
class ProfileForm(ModelForm):
class Meta:
model=UserProfile
exclude=('user',)
#views.py
def UserProfileView(request, username):
context_dict = {}
usercompany = get_object_or_404(Company, user=userprofile)
context_dict = {'usercompany': usercompany}
return render_to_response('profile_detail.html', context_dict, RequestContext(request))