我的应用有一个自定义用户。它可以与标准设置菜单配合使用:http://localhost:8888/admin/users/
但是我创建了一个带有ModelAdmin类的菜单,它给出了错误的URL:http://localhost:8888/admin/users/user/
from .models import User
class UserAdmin(ModelAdmin):
model = User
实际网址: / admin / users / user / 引发 ValueError
ValueError at /admin/users/user/
invalid literal for int() with base 10: 'user'
Request Method: GET
Request URL: http://localhost:8888/admin/users/user/
Django Version: 2.0.9
Exception Type: ValueError
Exception Value:
invalid literal for int() with base 10: 'user'
Exception Location: /home/lm/proyectos/sebusca/sebusca_django/env/lib/python3.6/site-packages/django/db/models/fields/__init__.py in get_prep_value, line 947
Python Executable: /home/lm/proyectos/sebusca/sebusca_django/env/bin/python
...
Local vars
Variable Value
args ('user',)
kwargs {}
request <WSGIRequest: GET '/admin/users/user/'>
view_func <function edit at 0x7f0948213f28>
我的用户模型:
class User(AbstractUser):
centro = models.ForeignKey('CentroEducativo', on_delete=models.SET_NULL, null=True)
def __str__(self):
return self.email
class CentroEducativo(models.Model):
pass
实际返回的是用户模型
django.contrib.auth.get_user_model()