UserProfile作为xadmin中的外键没有显示选项

时间:2017-11-19 01:34:41

标签: django

class UserProfile(AbstractUser):
nick_name=models.CharField(max_length=50,verbose_name='昵称')
birthday=models.DateTimeField(verbose_name='生日',null=True,blank=True)
gender=models.CharField(max_length=50,choices=(('male',u'男'),('female',u'女')),default=('male',u'男'))
address=models.CharField(max_length=100,default=u'')
mobile=models.CharField(max_length=11,null=True,blank=True)
image=models.ImageField(upload_to='image/%Y/%m',default=u'image/default.png',max_length=100)

class Meta:
    verbose_name=u'用户信息'
    verbose_name_plural=verbose_name

def __unicode__(self):
    return self.username


class UserCourse(models.Model):
user = models.ForeignKey(UserProfile, verbose_name=u'用户')
course = models.ForeignKey(Course, verbose_name=u'课程')
add_time=models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')

class Meta:
    verbose_name = u'用户课程'
    verbose_name_plural = verbose_name

the filter filed is search ,why is it option list?

they are all foreign key, why the first line are search and second line are option?

1 个答案:

答案 0 :(得分:0)

您可以在选择框中输入用户名,然后它会显示U选项;

这是由xadmin / plugins / auth.py

引起的
class UserAdmin(object):
change_user_password_template = None
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
list_filter = ('is_staff', 'is_superuser', 'is_active')
search_fields = ('username', 'first_name', 'last_name', 'email')
ordering = ('username',)
style_fields = {'user_permissions': 'm2m_transfer'}
model_icon = 'fa fa-user'
relfield_style = 'fk-ajax'  # comments here if u prefer select mode

您可以更改源代码