Django one model for two model form
up vote
0
down vote
favorite
I am newbie on Django. I have one model and two forms that can be accessed with different url. I have two different table on my database when I fill forms. What I want is to have one table on the database. What should I do?
Here is my forms:
class customerForm(forms.ModelForm):
class Meta:
model = customerInfoModel
fields = (
"customerName",
)
class addCustomerForm(forms.ModelForm):
class Meta:
model = customerInfoModel
fields = (
"user",
"passwd",
)
Here is my model:
class customerInfoModel(models.Model):
customerName = models.CharField(max_length = 100)
user = models.CharField(max_length = 50)
passwd = models.CharField(max_length = 20)
Views.py
@login_required
def addCustomer(request):
form = customerForm(request.POST or None)
content = {"form" : form,}
if form.is_valid():
form.save()
name = form.cleaned_data['customerName']
messages.success(request,"{} successfully added.".format(name))
return redirect("addproduct")
else:
return render(request,"addcustomer.html",content)
@login_required
def addProduct(request):
form = addCustomerForm(request.POST or None)
content = {"form" : form,}
if form.is_valid():
form.save()
messages.success(request,"product successfully added.")
return redirect("addproduct")
return render(request,"addproduct.html",content)
EDIT:
If I fill both forms, I want to have two objects. One object using customerForm
should have an output of customername : 'kartal'
, user: ''
, passwd: ''
; the other object using addCustomerForm
has customername: ''
, user: 'test'
, passwd: 'test'
. I want one object something like that customername: 'kartal'
, user:'test'
, passwd:'test'
django forms model
New contributor
add a comment |
up vote
0
down vote
favorite
I am newbie on Django. I have one model and two forms that can be accessed with different url. I have two different table on my database when I fill forms. What I want is to have one table on the database. What should I do?
Here is my forms:
class customerForm(forms.ModelForm):
class Meta:
model = customerInfoModel
fields = (
"customerName",
)
class addCustomerForm(forms.ModelForm):
class Meta:
model = customerInfoModel
fields = (
"user",
"passwd",
)
Here is my model:
class customerInfoModel(models.Model):
customerName = models.CharField(max_length = 100)
user = models.CharField(max_length = 50)
passwd = models.CharField(max_length = 20)
Views.py
@login_required
def addCustomer(request):
form = customerForm(request.POST or None)
content = {"form" : form,}
if form.is_valid():
form.save()
name = form.cleaned_data['customerName']
messages.success(request,"{} successfully added.".format(name))
return redirect("addproduct")
else:
return render(request,"addcustomer.html",content)
@login_required
def addProduct(request):
form = addCustomerForm(request.POST or None)
content = {"form" : form,}
if form.is_valid():
form.save()
messages.success(request,"product successfully added.")
return redirect("addproduct")
return render(request,"addproduct.html",content)
EDIT:
If I fill both forms, I want to have two objects. One object using customerForm
should have an output of customername : 'kartal'
, user: ''
, passwd: ''
; the other object using addCustomerForm
has customername: ''
, user: 'test'
, passwd: 'test'
. I want one object something like that customername: 'kartal'
, user:'test'
, passwd:'test'
django forms model
New contributor
What is the issue you are facing? Add error details
– a_k_v
18 hours ago
can you share your views.py here?
– Vikas Gautam
18 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am newbie on Django. I have one model and two forms that can be accessed with different url. I have two different table on my database when I fill forms. What I want is to have one table on the database. What should I do?
Here is my forms:
class customerForm(forms.ModelForm):
class Meta:
model = customerInfoModel
fields = (
"customerName",
)
class addCustomerForm(forms.ModelForm):
class Meta:
model = customerInfoModel
fields = (
"user",
"passwd",
)
Here is my model:
class customerInfoModel(models.Model):
customerName = models.CharField(max_length = 100)
user = models.CharField(max_length = 50)
passwd = models.CharField(max_length = 20)
Views.py
@login_required
def addCustomer(request):
form = customerForm(request.POST or None)
content = {"form" : form,}
if form.is_valid():
form.save()
name = form.cleaned_data['customerName']
messages.success(request,"{} successfully added.".format(name))
return redirect("addproduct")
else:
return render(request,"addcustomer.html",content)
@login_required
def addProduct(request):
form = addCustomerForm(request.POST or None)
content = {"form" : form,}
if form.is_valid():
form.save()
messages.success(request,"product successfully added.")
return redirect("addproduct")
return render(request,"addproduct.html",content)
EDIT:
If I fill both forms, I want to have two objects. One object using customerForm
should have an output of customername : 'kartal'
, user: ''
, passwd: ''
; the other object using addCustomerForm
has customername: ''
, user: 'test'
, passwd: 'test'
. I want one object something like that customername: 'kartal'
, user:'test'
, passwd:'test'
django forms model
New contributor
I am newbie on Django. I have one model and two forms that can be accessed with different url. I have two different table on my database when I fill forms. What I want is to have one table on the database. What should I do?
Here is my forms:
class customerForm(forms.ModelForm):
class Meta:
model = customerInfoModel
fields = (
"customerName",
)
class addCustomerForm(forms.ModelForm):
class Meta:
model = customerInfoModel
fields = (
"user",
"passwd",
)
Here is my model:
class customerInfoModel(models.Model):
customerName = models.CharField(max_length = 100)
user = models.CharField(max_length = 50)
passwd = models.CharField(max_length = 20)
Views.py
@login_required
def addCustomer(request):
form = customerForm(request.POST or None)
content = {"form" : form,}
if form.is_valid():
form.save()
name = form.cleaned_data['customerName']
messages.success(request,"{} successfully added.".format(name))
return redirect("addproduct")
else:
return render(request,"addcustomer.html",content)
@login_required
def addProduct(request):
form = addCustomerForm(request.POST or None)
content = {"form" : form,}
if form.is_valid():
form.save()
messages.success(request,"product successfully added.")
return redirect("addproduct")
return render(request,"addproduct.html",content)
EDIT:
If I fill both forms, I want to have two objects. One object using customerForm
should have an output of customername : 'kartal'
, user: ''
, passwd: ''
; the other object using addCustomerForm
has customername: ''
, user: 'test'
, passwd: 'test'
. I want one object something like that customername: 'kartal'
, user:'test'
, passwd:'test'
django forms model
django forms model
New contributor
New contributor
edited 17 hours ago
New contributor
asked 18 hours ago
Kartal
12
12
New contributor
New contributor
What is the issue you are facing? Add error details
– a_k_v
18 hours ago
can you share your views.py here?
– Vikas Gautam
18 hours ago
add a comment |
What is the issue you are facing? Add error details
– a_k_v
18 hours ago
can you share your views.py here?
– Vikas Gautam
18 hours ago
What is the issue you are facing? Add error details
– a_k_v
18 hours ago
What is the issue you are facing? Add error details
– a_k_v
18 hours ago
can you share your views.py here?
– Vikas Gautam
18 hours ago
can you share your views.py here?
– Vikas Gautam
18 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Kartal is a new contributor. Be nice, and check out our Code of Conduct.
Kartal is a new contributor. Be nice, and check out our Code of Conduct.
Kartal is a new contributor. Be nice, and check out our Code of Conduct.
Kartal is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407522%2fdjango-one-model-for-two-model-form%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is the issue you are facing? Add error details
– a_k_v
18 hours ago
can you share your views.py here?
– Vikas Gautam
18 hours ago