admin py class ClientAdmin admin ModelAdmin list_display code name con

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#admin.py
class ClientAdmin(admin.ModelAdmin):
list_display = ('code', 'name', 'contract_type', 'address', 'telephone1', 'telephone2', 'fax', 'contact_person', 'email')
admin.site.register(Client, ClientAdmin)
#models.py
class Client(models.Model):
name = models.CharField(max_length=50)
contract_type = models.ForeignKey(ContractType)
address = models.CharField(max_length=100, blank=True)
telephone1 = models.CharField(max_length=15, blank=True)
telephone2 = models.CharField(max_length=15, blank=True)
fax = models.CharField(max_length=15, blank=True)
contact_person = models.CharField(max_length=50)
email = models.EmailField(blank=True)
code = models.IntegerField(editable=False)
def save(self):
if not self.id:
code = customer_code()
def customer_code(self):
return random.randint(1000, 9999)
def __unicode__(self):
return self.name
class Meta:
ordering = ['name']