Package: django-names
NamesNames is a reusable app for Django that provides mixins, models and form fields
to store a full name and its individual components. The following name
components are supported:Full nameTitleFirst nameMiddle nameLast nameSuffixNicknameNames officially supports the following:Python 3.6 - 3.7Django 1.11, 2.0 - 2.2Table of ContentsInstallationBasic UsageFeaturesName modelNameField model fieldNameModelMixin mixinSettingsInstallationTo install, simply usepipenv(or pip):>>>pipenvinstalldjango-namesAddnamesto yourINSTALLED_APPSsetting:INSTALLED_APPS=[..."names",]Run migrations:>>>pythonmanage.pymigratenamesBasic Usage>>>fromnames.modelsimportName
>>>name=Name.objects.create(full="Natalia Alianovna 'Natasha' Romanova")>>>name.full'Natalia Alianovna Romanova (Natasha)'>>>name.first'Natalia'>>>name.middle'Alianovna'>>>name.last'Romanova'>>>name.nickname'Natasha'FeaturesNames was designed to be flexible. It comes with three primary features:Name: A model that parses and stores full names.NameField: A model field that provides a one-to-one relationship to aNameinstance.NameModelMixin: A mixin that can be used to extend existing models.NamemodelTheNamemodel contains fields and methods that store a full name and its
individual components.>>>fromnames.modelsimportName
>>>name=Name.objects.create(full="Anthony Edward Stark (Tony)")>>>name
<Name:AnthonyEdwardStark(Tony)>
>>>name.full'Anthony Edward Stark (Tony)'>>>name.title''>>>name.first'Anthony'>>>name.middle'Edward'>>>name.last'Stark'>>>name.suffix''>>>name.nickname'Tony'When you update an individual name component, the full name updates
automatically when the instance is saved.>>>name.nickname="Iron Man">>>name.save()>>>name.full'Anthony Edward Stark (Iron Man)'NameFieldmodel fieldNameFieldhas a one-to-one relationship to aNameinstance.fromnames.fieldsimportNameFieldclassUser(models.Model):name=NameField(on_delete=models.CASCADE)>>>fromnames.modelsimportName
>>>name=Name.objects.create(full="Carol Susan Jane Danvers")>>>User=User.objects.create(name=name)>>>user.name.full'Carol Susan Jane Danvers'NameModelMixinmixinNameinherits its functionality from theNameModelMixinmixin. You can
use this mixin to extend existing models to avoid adding a field with a
one-to-one relationship or additional database tables.fromnames.mixinsimportNameModelMixinclassUser(NameModelMixin):pass>>>user=User.objects.create(full="General Nicholas Joseph 'Nick' Fury")>>>user.full'General Nicholas Joseph Fury (Nick)'>>>user.title'General'SettingsNames uses theNAME_SETTINGSnamespace for all settings. The following settings
are supported:MAX_LENGTHSTRING_FORMATEMPTY_ATTRIBUTE_DEFAULTOPTIONSTITLESFIRST_NAME_TITLESSUFFIX_ACRONYMSSUFFIX_NOT_ACRONYMSCONJUNCTIONSPREFIXESCAPITALIZATION_EXCEPTIONSREGEXESMAX_LENGTHtype <int>Max length of eachCharFielddefined in theNameModelMixinmixin.Default:100STRING_FORMATtype <str>Sets the output string for thefullfield.Default"{title}{first}{middle}{last}{suffix}({nickname})"Learn moreChange the output string with string formattingEMPTY_ATTRIBUTE_DEFAULTtype <str>Value returned by empty name attributes.Default""# empty stringOPTIONStype <dict>Handles recognition of titles, prefixes, suffixes and conjunctions. TheOPTIONSsetting is
very powerful and can be used to customize how you parse names.Default"OPTIONS":{"TITLES":TITLES,"SUFFIX_NOT_ACRONYMS":SUFFIX_NOT_ACRONYMS,"CONJUNCTIONS":CONJUNCTIONS,"PREFIXES":PREFIXES,"CAPITALIZATION_EXCEPTIONS":CAPITALIZATION_EXCEPTIONS,"REGEXES":REGEXES,}Options are imported frompython-nameparser, which is the library used to parse names.Learn moreEditable attributes