These are chat archives for django/django

Jul 2018
Jul 28 2018 05:24
How do i use Group features which is not now in channels 2?
class IncomingDataManager:
    def __init__(self, device_token, user, timestamp=None):
        self.device_token = device_token
        if not (user is None or isinstance(user, User)):
            user = User.objects.get(id=user)
        self.user = user
        self.ios = dict()
        if timestamp is None:
            timestamp = datetime.utcnow()
        self.timestamp = timestamp

    def sendToWebSocketClients(self):
          for deviceio_token, content in self.ios.items():
                  group_name = "{}-{}".format(self.device_token, deviceio_token)
                  message = {
                      "device_token": self.device_token,
                      "io_token": deviceio_token,
                      "value": str(content['value']),
                      "date_time": str(self.timestamp),
                      "io_name": content['name']
                  text = {
                      "text": json.dumps(message)
              except Exception as e:
                  '''Do nothing'''
Jul 28 2018 07:07
Hello Everyone what is best way to do api versioning for posting data in django app. I have a model which has field speed and old client send data in km/h new client send data in mph. Front end application now needs to show data in mph for both old and new clients. what's the best way to do it?
I know I can have different serializers for each version to fetch data and convert old clients data to mph. Is there better way to do this while storing in db? Like at insertion time update field in model to store mph?
Jul 28 2018 08:42
I have a following kind of User and Role model. When I create a user form admin and then try to login from api i get unable to login error but it works if I create user from api instead of admin
from django.db import models
from django.dispatch import receiver
from django.contrib.auth.models import AbstractUser

from rest_framework.authtoken.models import Token

class Role(models.Model):

        ('agent', 'Agent'),
        ('agency', 'Agency'),
        ('manufacturer', 'Manufacturer'),
    role = models.CharField(max_length=15, choices=ROLE_CHOICES)

    def __str__(self):
        return self.role

class User(AbstractUser):

    role = models.ForeignKey(

    def __str__(self):
        return self.username

    # def save(self, *args, **kwargs):
    #     if not  # the instance is created
    #         self.role, created = Role.objects.get_or_create(role="agent")
    #     return super().save(*args, **kwargs)

@receiver(models.signals.post_save, sender=User)
def add_role_to_user(sender, instance, **kwargs):
    print ('instance in add role', instance)
    if kwargs.get('created'):
            role = Role.objects.get(user=instance)
            print('role', role)
        except Role.DoesNotExist:
            token = Token.objects.get(user=instance)
            print ('token', token)
        except Token.DoesNotExist:

# @receiver(models.signals.post_save, sender=User)
# def save_user_role(sender, instance, **kwargs):
#     print ('instance', instance)
When i query user model, i get that user but i cannot login
user = authenticate(**data) this returns none
Jul 28 2018 10:38
what can be the reason for this?
Sanjeev Sharma
Jul 28 2018 13:57
@funkybob I followed a tutorial online and installed boto3 and django-storages. I am using S3 to store my data. DB is in postgresql. In brief, its AWS EB + S3 + Postgresql.
Jul 28 2018 18:11
hello i have a project in mind anyone interested plese pm me and i need only serious peoply people