I wouldn’t save alpha in the database. I would use a property on the model or annotate the field to the object manager.
Property:
class Guest(models.Model):
@property
def alpha(self):
return self.lname[0] if self.lname else ''
Or on the object manager:
class GuestManager(models.Manager):
def get_queryset(self):
return super().get_queryset().annotate(alpha=Left('lname', 1))
class Guest(models.Model):
objects = GuestManager()
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
django-users...@googlegroups.com.
To post to this group, send email to
django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/45a3e32d-29d7-4129-896b-01698beec3e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.