Django admin: make field editable in add but not edit

后端 未结 3 469
南笙
南笙 2020-12-24 11:19

I\'ve got a model similar to this:

class Product(models.Model):
    third_party_id = models.CharField(max_length=64, blank=False, unique=True)
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-24 12:14

    The above is helpful (shanyu's answer using get_readonly_fields), however it does not work properly if used in "StackedInline". The result is two copies of whatever field is marked readonly, and it is not editable in the "add" instance. See this bug: https://code.djangoproject.com/ticket/15602

    Hope this saves someone some searching!

提交回复
热议问题