Skip to content

Core library for Nexus django projects. Common utils needed across many apps

License

Notifications You must be signed in to change notification settings

chopdgd/django-genomix

Repository files navigation

Django GenomiX

https://travis-ci.org/chopdgd/django-genomix.svg?branch=develop Updates Python 3

Core library for Nexus django projects

Documentation

The full documentation is at https://django-genomix.readthedocs.io.

Quickstart

Install Django GenomiX:

pip install django-genomix

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'genomix',
    ...
)

Features

  1. DisplayChoiceField - display representation values for choice fields in REST APIs.:
from genomix.fields import DisplayChoiceField
from rest_framework import serializers

from . import choices


class ExampleSerializer(serializers.ModelSerializer):

    status = DisplayChoiceField(choices=choices.STATUS_OPTIONS)
  1. UserRelatedField - display username for a REST API with a user relation.:
from django.contrib.auth import get_user_model

from genomix.fields import UserRelatedField
from rest_framework import serializers


class ExampleSerializer(serializers.ModelSerializer):

    user = UserRelatedField(queryset=get_user_model().objects.all())
  1. ContentRelatedField - display ContentType model for a REST API using a generic relation.:
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType

from genomix.fields import ContentRelatedField
from rest_framework import serializers


class ExampleSerializer(serializers.ModelSerializer):

    content_type = ContentRelatedField(queryset=ContentType.objects.all())
  1. DisplayChoiceFilter - Filter by representation values in a REST API.:
import django_filters
from genomix.filters import DisplayChoiceFilter

from . import choices


class ExampleFilter(django_filters.rest_framework.FilterSet):

    source = DisplayChoiceFilter(choices=choices.SOURCES)

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package: