How to add field in Token Model in Django Rest Framework Authtoken -


i'm using rest_framework.authtoken.models token. can see 3 fields key, created_at , user_id.

background of app:

i use chrome app client app, want use token authentication connect apis in django rest framework. , want store user_id , company_id in authtoken_token table. store token key in chrome app localstorage,

enter image description here

  1. my question how can add field company_id model? couldn't find docs or articles this.

  2. i've jamie's answer in this article subclass model don't know how.

thanks!

define own authentication method: settings.py

    'default_authentication_classes': (     'my_project.my_app.authentication.myowntokenauthentication',      ), 

authentication.py

from rest_framework.authentication import tokenauthentication my_project.my_app.models.token import myowntoken  class myowntokenauthentication(tokenauthentication):     model = myowntoken 

model.py

import binascii import os  django.db import models django.utils.translation import ugettext_lazy _ my_project.companies.models import company   class myowntoken(models.model):     """     default authorization token model.     """     key = models.charfield(_("key"), max_length=40, primary_key=true)      company = models.onetoonefield(         company, related_name='auth_token',         on_delete=models.cascade, verbose_name="company"     )     created = models.datetimefield(_("created"), auto_now_add=true)      class meta:         verbose_name = _("token")         verbose_name_plural = _("tokens")      def save(self, *args, **kwargs):         if not self.key:             self.key = self.generate_key()         return super(myowntoken, self).save(*args, **kwargs)      def generate_key(self):         return binascii.hexlify(os.urandom(20)).decode()      def __str__(self):         return self.keydefine own authentication method: 

settings.py

    'default_authentication_classes': (     'my_project.my_app.authentication.myowntokenauthentication',      ), 

authentication.py

from rest_framework.authentication import tokenauthentication my_project.my_app.models.token import myowntoken  class myowntokenauthentication(tokenauthentication):     model = myowntoken 

model.py

import binascii import os  django.db import models django.utils.translation import ugettext_lazy _ my_project.companies.models import company   class myowntoken(models.model):     """     default authorization token model.     """     key = models.charfield(_("key"), max_length=40, primary_key=true)      company = models.onetoonefield(         company, related_name='auth_token',         on_delete=models.cascade, verbose_name="company"     )     created = models.datetimefield(_("created"), auto_now_add=true)      class meta:         verbose_name = _("token")         verbose_name_plural = _("tokens")      def save(self, *args, **kwargs):         if not self.key:             self.key = self.generate_key()         return super(myowntoken, self).save(*args, **kwargs)      def generate_key(self):         return binascii.hexlify(os.urandom(20)).decode()      def __str__(self):         return self.key