Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jblac
Last active October 25, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jblac/87338185b562b5b6f9e5493356db544b to your computer and use it in GitHub Desktop.
Save jblac/87338185b562b5b6f9e5493356db544b to your computer and use it in GitHub Desktop.
./
..apibase/
... admin.py
... apps.py
... models.py
... serializers.py
... tests.py
... urls.py
... views.py
.. projekt
... settings.py
... urls.py
... router.py
.. legassy
... admin.py
... apps.py
... models.py
... serializers.py
... tests.py
... urls.py
... views.py
./manage.py runserver 0.0.0.0:8000
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f13fc0d4f28>
Traceback (most recent call last):
File "/usr/local/lib/venvs/snapi/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/venvs/snapi/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/venvs/snapi/lib/python3.6/site-packages/django/core/management/base.py", line 405, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
apibase.User.company_id: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.
from django.db import models
from django.contrib.auth.models import AbstractUser
from legassy.models import Company
class User(AbstractUser):
"""
Overrides the default Django user model.
Anything specific to the usage of the user, as it pertains to
the Django application, MUST be added here.
"""
company_id = models.IntegerField(choices=Company.objects.all())
I have an application, written in PHP, that is currently running in production. I am now, utilzing python3 and Django
to write a JSON API for the application. To do this without causing any problems, i've opted to use 2 databases.
I've overridden the default User model for Django, and attempted to add an InterField to the user model, containing
the company_id with choices boxes containing the id and name of all the companies from database 2. I know Django doesn't
support cross-database foreign key, so have decided an integer field will work just fine.
Just not sure how to make the choices a valid tuple for this slim usecase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment