如何自定义django管理模型?

时间:2016-03-31 07:51:52

标签: django-admin

我想在内置管理模型的django中添加以下模型以进行注册。

class ClientDetails(models.Model):
    globalmasterid = models.IntegerField()
    clientid = models.IntegerField()
    password = models.CharField(max_length = 45,blank=False)
    loginid = models.CharField(max_length = 45,blank=True, default='')
    clientname = models.CharField(max_length = 45,blank=True, default='')
    clientdba = models.CharField(max_length = 45,blank=True, default='')
    clientaddress1 = models.CharField(max_length = 45,blank=True, default='')
    city =  models.CharField(max_length = 45,blank=True, default='')
    state = models.CharField(max_length = 45,blank=True, default='')
    zip = models.CharField(max_length = 45,blank=True, default='')
    phone = models.CharField(max_length = 45,blank=True, default='')
    clienttax_number = models.CharField(max_length = 45,blank=True, default='')
    clienttaxtype = models.IntegerField()
    signupdate = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'clientdetails'
        managed= False

我有什么方法可以做到这一点......任何一点帮助或建议都将受到赞赏..

1 个答案:

答案 0 :(得分:1)

def get_admin_absolute_url(self):
    if self.pk:
        return resolve_url('admin:appname_modelname_change', self.pk)

def admin_link(self):
    if not self.pk:
        return ''
    return ('<a href={}>{}</a>').format(self.get_admin_absolute_url(), self.name)
    # return ('<a href = "{}"> Link to:</a>').format(self.get_admin_absolute_url())

admin_link.allow_tags = True
admin_link.short_discription = ''

将此添加到模型的末尾并登录到管理站点