python - create a django user while creating a records for model -


models.py below,

from django.db import models django.contrib.auth.models import user  class members(models.model):      auto_id = models.autofield(primary_key=true)     member_name = models.onetoonefield(user)     owner = models.foreignkey('auth.user', related_name='webapi', on_delete=models.cascade)     father_name = models.charfield(max_length=25, blank=false, default='')     wife_name = models.charfield(max_length=25, blank=false, default='')     number_of_child = models.integerfield(blank=true)     address_line_1 = models.charfield(max_length=40, blank=false, default='')     address_line_2 = models.charfield(max_length=40, blank=true, default='')     city = models.charfield(max_length=25, blank=false, default='')      class meta:         ordering = ('member_name',) 

now above has been linked django auth users table , in steriliser shows existing django users , have choose 1 during submit.

but requirement admin user login , provide member_name manually should automatically create django user also

django-annoying has feature this, autoonetoonefield.

sample github:

from annoying.fields import autoonetoonefield  class myprofile(models.model):     user = autoonetoonefield(user, primary_key=true) 

this should automatically create user.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -