B
B
Black back2020-04-27 15:15:59
Django
Black back, 2020-04-27 15:15:59

How can I save a user whose value is NOT NULL?

I can’t save through the form (forms)
That is, in the user, leave empty because of this, an error ( NOT NULL ) comes out, how can I get around

number = models.CharField('Номер телефона', max_length=12, unique=True)
    fname = models.CharField('Фамиля', max_length=25)
    name = models.CharField( max_length=25)
    lname = models.CharField( max_length=25)
    pin = models.CharField( max_length=6)
    address = models.CharField( max_length=50, unique=True)
    birtday = models.DateField()
    file = models.FileField( upload_to='media/')
    user = models.OneToOneField(User, on_delete=models.CASCADE)


forms.py
class NewMann(forms.ModelForm):
 class Meta:
        model = Man
        fields = (
            'number', 'fname','pin' ,'address','name', 'lname', 'birtday',
            'file')


views.py
if request.method == 'POST':
        form = NewMann(request.POST, request.FILES)
        if form.is_valid():
            user = User.objects.create_user(username=request.POST['name'], password=request.POST['pin'])
            if user is not None:
                form.save()
                print('save')
                auth.login(request,user)
                return HttpResponse("<h2>зарегистрировался</h2>")
            else:
                args['login_error'] = "Пользователь не найден"
                return render_to_response('registration/registration.html',args)
        else:
            return render(request,'registration/registration.html',{'form':form})
    else:
        form = NewMann()
        return render(request,'registration/registration.html',{'form':form})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-04-27
@tumbler

Pass "Not NULL"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question