1๐
โ
You can create a method which returns the id
of the object.
models.py
class POS(models.Model):
# your fields...
def get_id(self):
return self.id
Now, add this method to fields
and readonly_fields
of PosInLine
class.
admin.py
class PosInLine(admin.StackedInline):
model = POS
extra = 0
fields = ('get_id', 'name',)
readonly_fields = ('get_id',)
Note: The id
shown for a new object will not be a correct id
. On saving that object, a new correct id
will be assigned to the object.
๐คxyres
1๐
If your id is also your primary key, you can display that instead:
class PosInLine(admin.StackedInline):
model = POS
extra = 0
fields = ('name',)
readonly_fields = ('pk',)
๐คPaddi
- [Answered ]-How to prevent users from editing or deleting other user posts ? Django
- [Answered ]-Custom DRF list function not returning some of the dict key/value pairs
- [Answered ]-How to populate django admin form from model property?
- [Answered ]-Match file path in url regex
Source:stackexchange.com