you can use in default callable object, something, like function, but not the lambda:
set_name(obj):
return f'Item #{obj}' # this is not work for new object
class Items(models.Model):
# item_id = models.AutoField(primary_key=True) you dont need it, it will be created automatically
item_name = models.CharField(
max_length=100, default=set_name.format(item_id)
)
One problem - this is not work for new object, you always will receive None. But your item_name is static, that's why you can made a property, for example:
class Items(models.Model):
# item_id = models.AutoField(primary_key=True) you don't need it, it will be created automatically
name = models.CharField(
max_length=100, null=false, blank=true, default='')
@property
def item_name(self):
return f'{self.name or 'Item'} #{self.pk or "New object"}'
Other possibility is - to override __str__ or __repr__:
class Items(models.Model):
# item_id you don't need it, it will be created automatically
# item_name you don't need it too
def __str__(self):
return f'Item #{self.pk}'
def __repr__(self):
return f'{self}'
@property
def item_name(self):
return f'{self}'