Django'da User
uzantısını genişletmeye çalışıyorum. Bu yeni User
, dahili User
'dan daha fazla özniteliğe sahip olmalı ve bazılarının kayıt sırasında gerekli olması gerekir. Ayrıca, bu yeni kullanıcı türünü Admin
'da görmek istiyorum. Resmi eğitici ve this youtube videosunu izledim ancak bir error
var.Django - AttributeError: 'UserProfile' nesnesinin 'urls' özniteliği yok
Django'da yeniyim, bu yüzden sorunun nerede olabileceğini bulamıyorum. Neyin yanlış olduğunu biliyor musun?
DÜZENLEME: Sunucuyu durdurmayı denedim ve makemigrations
- aynı hata oluştu.
CMD:
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages\venv\
lib\site-packages\django\core\urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages\venv\
lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages\venv\
lib\site-packages\django\core\urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages\Solut
ionsForLanguagesProject\urls.py", line 22, in <module>
url(r'^admin/', admin.site.urls),
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages\venv\
lib\site-packages\django\contrib\admin\sites.py", line 303, in urls
return self.get_urls(), 'admin', self.name
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages\venv\
lib\site-packages\django\contrib\admin\sites.py", line 287, in get_urls
url(r'^%s/%s/' % (model._meta.app_label, model._meta.model_name), include(mo
del_admin.urls)),
AttributeError: 'UserProfile' object has no attribute 'urls'
MODELS.PY:
...
from django.db.models.signals import post_save
...
class UserProfile(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE)
first_name = models.CharField(max_length=40)
surname = models.CharField(max_length=40)
email = models.EmailField()
telephone = models.CharField(max_length=40)
def __unicode__(self):
return '{} {}'.format(self.first_name,self.surname)
def create_profile_user_callback(sender,instance, **kwargs):
profile, new = UserProfile.objects.get_or_create(user=instance)
post_save.connect(create_profile_user_callback, User)
ADMIN.PY:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from models import *
from .models import UserProfile
admin.site.register(AdminContact)
class UserProfileInline(admin.StackedInline):
model = UserProfile
can_delete = False
verbose_name_plural = 'User_Profile'
class UserAdmin(BaseUserAdmin):
inlines = (UserProfileInline,)
admin.site.unregister(User)
admin.site.register(User,UserProfile)
URLS.PY: admin.py olarak
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^about', TemplateView.as_view(template_name='static/about-us.html')),
url(r'^terms-and-conditions', TemplateView.as_view(template_name='static/terms-and-conditions.html')),
url(r'^faq', TemplateView.as_view(template_name='static/faq.html')),
url(r'^$', views.index),
url(r'^contact-us', views.contact_us),
]
registration_patterns = [
url(r'register', views.register),
url(r'register_success', views.register_success),
]
urlpatterns += registration_patterns