0
class Sale(models.Model):

    contract_id = models.CharField(max_length=255,primary_key=True)
    company = models.CharField(max_length=255)

    def __unicode__
        return self.contract_id

_______________________________

you can add contract_id and company in "Add Page", but in the "Change Page",the contract_id is readonly,you can only change the company

falsetru
  • 357,413
  • 63
  • 732
  • 636
Richard Yang
  • 101
  • 7
  • possible duplicate of [In a django form, How to make a field readonly (or disabled) so that it cannot be edited?](http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-b) – mariodev Sep 23 '13 at 07:43

1 Answers1

0

Please see below code
Go to your admin.py file

class SaleAdmin(admin.ModelAdmin):
    """ sale creation template """
    list_display = ['contract_id', 'company']
    def get_readonly_fields(self, request, obj=None):
        """ contract_id is readonly after save """
        if obj:
            return self.readonly_fields + ('contract_id',)
        return self.readonly_fields
Prashant Gaur
  • 9,540
  • 10
  • 49
  • 71