django rest framework - created new custom user model, having error while inserting values -


i developing app in angular , django. backend developing backend in django rest_framework. , have written custom user model because have own field used in app. while sending json data api, getting error while saving data.

i wrote own manager.py, getting error while inserting data database

exception type: keyerror exception value:
'groups' exception location: /home/mayur/documents/codematrix/backend/venv/lib/python3.5/site-packages/rest_framework/fields.py in get_attribute, line 101

code here

models.py

class user(abstractbaseuser, permissionsmixin): email = models.emailfield(_('email address'), unique=true) first_name = models.charfield(_('first name'), max_length=30, blank=true) last_name = models.charfield(_('last name'), max_length=30, blank=true) date_joined = models.datetimefield(_('date joined'), auto_now_add=true)  objects = usermanager()  username_field = 'email' required_fields = []  class meta:     verbose_name = _('user')     verbose_name_plural = _('users')  def get_full_name(self):     '''     returns first_name plus last_name, space in between.     '''     full_name = '%s %s' % (self.first_name, self.last_name)     return full_name.strip()  def get_short_name(self):     '''     returns short name user.     '''     return self.first_name 

serializers.py

class userserializer(modelserializer): class meta:     model = user     fields = '__all__' 

views.py

class userlist(apiview): """ list users, or create new user. """ def get(self, request, format=none):     users = user.objects.all()     serializer = userserializer(users, many=true)     return response(serializer.data)  def post(self, request, format=none):     serializer = userserializer(data=request.data)     if serializer.is_valid():         print(serializer.data)         # serializer.save()         return response(serializer.data, status=status.http_201_created)     return response(serializer.errors, status=status.http_400_bad_request)  def delete(self, request, pk, format=none):     user = self.get_object(pk)     user.delete()     return response(status=status.http_204_no_content) 

managers.py

class usermanager(baseusermanager): use_in_migrations = true  def _create_user(self, email, password, **extra_fields):     """     creates , saves user given email , password.     """     if not email:         raise valueerror('the given email must set')     email = self.normalize_email(email)     user = self.model(email=email, **extra_fields)     user.set_password(password)     user.save(using=self._db)     return user  def create_user(self, email, password=none, **extra_fields):     extra_fields.setdefault('is_superuser', false)     return self._create_user(email, password, **extra_fields)  def create_superuser(self, email, password, **extra_fields):     extra_fields.setdefault('is_superuser', true)      if extra_fields.get('is_superuser') not true:         raise valueerror('superuser must have is_superuser=true.')      return self._create_user(email, password, **extra_fields) 


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -