i hope can me this, i've been trying make form autofills field using concatenation of 2 fields on same form, no success, model , form
class doctor(models.model): name_doctor = models.charfield(max_length=20) last_doctor = models.charfield(max_length=20) email_doctor = models.emailfield() p_doctor = models.charfield(max_length=10) id_doctor = models.charfield(max_length=30, blank=true) def __str__(self): return '%s %s' % (self.name_doctor, self.last_doctor)
and form:
class adoctor(forms.modelform): class meta: model = doctor fields = ('name_doctor', 'last_doctor', 'email_doctor', 'p_doctor', 'id_doctor') labels = { 'name_doctor': ('name'), 'last_doctor': ('last name'), 'email_doctor': ('email'), 'p_doctor': ('phone'), 'id_doctor': ('id'), }
how can override save when send form field id_doctor fills concatenation of name_doctor + last_doctor ?
the answer is: don't bother.
whenever can generate item of data based on content of 1 or more fields on table, not need create field it. , name_doctor
+ last_doctor
classic example of this.
your model has name_doctor field last_doctor field, it's trivial matter display them combining them together. there no need save database , shouldn't.
edit: can produce custom combination of fields adding method model example:
class doctor(models.model): def concat_fields(self): return self.name_doctor + self.last_doctor def quasi_unique_id(self): return self.name_doctor[0:2] + self.last_doctor[0:2] + id_order(some_other_model)