2

Here's my issue guys. I have a store user that can log to his site and view all kinds of data related to his store. In his store he has, let's say 10 android billing devices that send bills to him. Now I need to create a custom authentication in Django REST framework that will authenticate android devices with their id_number and type fields (not store user's username & password) and assign a token to them (each individually) and allow them to POST, GET, PUT etc.. Is that possible?

Store(models.Model):
    user = models.ForeignKey(User, default=1)

AndroidDevice(models.Model):
    id_number = models.CharField()
    type = models.CharField()
    store= models.ForeignKey(Store)
Ray Tango
  • 107
  • 9

2 Answers2

0

yes... it is possible

Note: use a custom authentication and create your own Token Model that is related to you AndroidDevice model instead of the User Model or whatever you need to do (multiple tokens, tokens that expires, etc.). Read the DRF source code to get inspired :)

Hope this helps

pleasedontbelong
  • 19,542
  • 12
  • 53
  • 77
  • Thanks for your input pdb. I'll try what you suggested. I've read every word of DRF documentation but it's still abit vague to me since I'm a beginner at Django & DRF... – Ray Tango Aug 31 '16 at 22:03
0

What I ended up doing was adding another field to my model with OneToOne relationship to User model. That way I was able to use DRF's built in authentication. Also I overrided the save method for that model so when the new instance is created it creates a new User object with his username/password set to values from id_number/type fields.

Ray Tango
  • 107
  • 9