dhananjay_shingote
dhananjay_shingote

Reputation: 419

How to customize django admin models?

I want to add below models in django built in admin models for regisration.

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

IS there any way I can do this ...Any little help or suggestion will be appreciated..

Upvotes: 0

Views: 40

Answers (1)

Ohad the Lad
Ohad the Lad

Reputation: 1929

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 = ''

add this to the end of your model and log to admin site

Upvotes: 1

Related Questions