0

I have used function based View to get data from post Request. I need to get many data that also include a primary key field too. I need to push data into two models. While doing so, I encountered error.

#accounts models.py
from django.db import models
class User(models.Model):
    user_id = models.CharField(max_length=50,)
    name = models.CharField(max_length=200)
    phone = models.CharField(max_length=200)
    email = models.EmailField(max_length=254)

#app models.py
from accounts.models import User #from accounts models.py
class job(models.Model):
    user = models.ForeignKey(User, on_delete=models.DO_NOTHING)
    ......

#views.py
data = job(.....,map_link=map_link,user_id=user_id)
        data.save()
        info=User(name=name,email=email,phone=phone,user_id=user_id)
        info.save()

Error Message: http://dpaste.com/03Z0EPB

enter image description here

Aayush Bhattarai
  • 510
  • 1
  • 7
  • 16
  • Within views.py, You're assigning user_id before the user with respective user_id has been created. – alter123 Jul 10 '19 at 05:54
  • Thanks that's work but can you tell me how to pick and match the value of dropdown of HTML and Django admin. – Aayush Bhattarai Jul 10 '19 at 07:52
  • It's just a suggestion, but you can use the default AbstractUser model and add the aditional field you need, which will be going to give all the default user model features – shekhar Jul 10 '19 at 10:25

0 Answers0