我不知道为什么这会发生在我的网站上......正如我的观点,我正在做所有这些事情。但是应该有一些隐藏在我眼前的东西。
这是我的models.py和admin.py文件。
models.py:
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.dispatch import receiver
from . import managers
class Profile(models.Model):
# Relations
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
related_name='profile',
verbose_name=_('user'),
on_delete=models.CASCADE
)
# Attributes - Mandatory
interaction = models.PositiveIntegerField(
default=0,
verbose_name=_('interaction')
)
# Custom Properties
@property
def username(self):
return self.user.username
# Methods
# Meta and String
class Meta:
verbose_name = _("Profile"),
verbose_name_plural = _("Profiles"),
ordering = ('user',)
def __str__(self):
return self.user.username
@receiver(models.signals.post_save, sender=settings.AUTH_USER_MODEL)
def create_profile_for_new_user(sender, **kwargs):
if kwargs['created']:
profile = Profile(user=kwargs['instance'])
profile.save()
admin.py:
from django.contrib import admin
from . import models
@admin.register(models.Profile)
class ProfileAdmin(admin.ModelAdmin):
list_display = ['username', 'interaction']
答案 0 :(得分:1)
声明后的逗号...示例:
>>> a = ("SAFDFD"),
>>> _
>>> ("SAFDFD",)