A Django application that provides a university institution field for models and a serializer.
pip install django-institutions- Add
django_institutionsto yourINSTALLED_APPS
An institution field for Django models with choices from:
https://github.com/Hipo/university-domains-list
InstitutionField is based on Django's CharField.
Consider the following model user InstitutionField:
from django.db import models
from django_institutions.fields import InstitutionField
class User(models.Model):
name = models.CharField(max_length=255)
institution = InstitutionField()A User instance will have a institution attribute where you can get the details of the institution.
>>> user = User(name='John Doe', institution='University of London')
>>> user.institution
Institution(name='University of London', country='United Kingdom', etc)
>>> user.institution.name
'University of London'
>>> user.institution.country
'United Kingdom'To serialize the institution field, you can use the InstitutionField serializer field. For example:
from django_institutions.serializer_fields import InstitutionField
class UserSerializer(serializers.ModelSerializer):
institution = InstitutionField()The serialized output will look like the following:
{"name": "University of London"}Either the dict output or simply the name of the institution is acceptable as intputs.
This project is inspired by django-countries
Thanks to SmileyChris for the inspiration.
The institution data is sourced from university-domains-list
This project is still very in early development. Help is welcome :)