Django model field -- populate_from Option for CharField -
just wan't ask if possible use populate_from option in charfield field prepopulate field other fields, example of slug field.
class post(models.model): ***name***= models.charfield(max_length=50) slug = extension_fields.autoslugfield(populate_from='***name***', blank=true) created = models.datetimefield(auto_now_add=true, editable=false) last_updated = models.datetimefield(auto_now=true, editable=false)
let say,
class employee(models.model): eid= models.charfield(primary_key = true) lastname = models.charfield(max_length=50) firstname = models.charfield(max_length=50) middlename = models.charfield(max_length=50, null=true)
now wan't add new charfield fullname. wan't fullname populated lastname, firstname , middlename fields.
fullname = models.charfield(populate_from = "***i don't know here***")
please help...
here's option not require overriding save
function:
class employee(models.model): def get_fullname(self): return '{} {} {}'.format(self.lastname, self.firstname, self.middlename) eid= models.charfield(primary_key = true) lastname = models.charfield(max_length=50) firstname = models.charfield(max_length=50) middlename = models.charfield(max_length=50, null=true) fullname = property(get_fullname)
this option great if don't need edit fullname
separately lastname
, firstname
, middlename
not display field in admin, stores result in database gets value when called
Comments
Post a Comment