A django app for institutions model fields
Project description
django-institutions
A Django application that provides a university institution field for models and a serializer.
Installation
pip install django-institutions
Usage
InstitutionField
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'
Django Rest Framework field
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()
REST output format
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.
Acknowledgements
This project is inspired by django-countries
Thanks to SmileyChris for the inspiration.
Data
The institution data is sourced from university-domains-list
Notes
This project is still very in early development. Help is welcome :)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_institutions-0.0.1.tar.gz
.
File metadata
- Download URL: django_institutions-0.0.1.tar.gz
- Upload date:
- Size: 205.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1b7add949eb65ad9f4764935447f68b5a8674cd959f13c10faeaf358716e830 |
|
MD5 | ab3e37f43c21f2621cfa547fdf1917dd |
|
BLAKE2b-256 | df28a9ed1124b4f0fc241c5ed6b9ac2fdb6e358c7c17f37f971c62a5aeb7ec00 |
File details
Details for the file django_institutions-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_institutions-0.0.1-py3-none-any.whl
- Upload date:
- Size: 210.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67c009de5236a92d986e78962b081b6b6ec15ff3f50cb6453a913f4ae3cce36c |
|
MD5 | 1b0502207b9c1f750f4c2706a2eacc53 |
|
BLAKE2b-256 | 0148740fc147eab45b8d0080b9383bea58f70d6d7db5100bdc9853633301bd83 |