I am working on a project similar to a stock market. In this project I have a model called Stock
which is as follows:
class Stock(models.Model):
_title = models.CharField(max_length=50)
_description = models.TextField()
_total_subs = models.IntegerField()
_sold_out_subs = models.IntegerField()
_created_at = models.DateTimeField(auto_now_add=True)
_updated_at = models.DateTimeField(auto_now=True)
_status = models.BooleanField()
Access to create new records for this model is to be supposed only through the Django admin panel, so in the admin.py file in my app I wrote a class to manage it called StockAdmin as follows:
class StockAdmin(admin.ModelAdmin):
list_display = []
readonly_fields = ['_sold_out_subs']
class Meta:
model = Stock
How can I make a _total_subs
so that it can be writable when it being create and then it should be in read-only fields?