models.py
from django.db import models
class booking(models.Model):
fname=models.CharField( max_length=50)
lname=models.CharField( max_length=50)
email=models.EmailField(max_length=254)
city=models.CharField(max_length=50)
state=models.CharField(max_length=50)
pin=models.IntegerField()
def __str__(self):
return self.fname
class approved(models.Model):
fname=models.CharField( max_length=50)
lname=models.CharField( max_length=50)
email=models.EmailField(max_length=254)
city=models.CharField(max_length=50)
state=models.CharField(max_length=50)
pin=models.IntegerField()
def __str__(self):
return self.fname
views.py
def adminp(request):
if 'form_rejected' in request.POST and request.method=="POST":
print("Went into reject")
p=booking.objects.filter(id=request.POST.get('object_id','')).delete()
print(p)
elif 'form_approved' in request.POST and request.method=="POST":
print("went in approve")
fname= booking.objects.filter(fname=request.POST.get('object_fname','')).values_list('fname')
lname= booking.objects.filter(lname=request.POST.get('object_lname','')).values_list('lname')
email= booking.objects.filter(email=request.POST.get('object_email','')).values_list('email')
city= booking.objects.filter(city=request.POST.get('object_city','')).values_list('city')
state= booking.objects.filter(state=request.POST.get('object_state','')).values_list('state')
pin= booking.objects.filter(pin=request.POST.get('object_pin','')).values_list('pin')
app= approved(fname=fname,lname=lname,email=email,city=city,state=state,pin=pin)
app.save()
print(fname,pin)
x=booking.objects.all()
params={'pro': x}
return render(request,'dbms/adminpanel.html',params)
template
<form action="" method="POST">
{% csrf_token %}
<div class="col"><p>Firstname: {{i.fname}}</p></div>
<div class="col"><p>Lastname: {{i.lname}}</p></div>
<div class="col"><p>Email: {{i.email}}</p></div>
<div class="col"><p>City: {{i.city}}</p></div>
<div class="col"><p>Pin: {{i.pin}}</p></div>
<input type="hidden" name="object_fname" value="{{ i.fname }}">
<input type="hidden" name="object_lname" value="{{ i.lname }}">
<input type="hidden" name="object_email" value="{{ i.email }}">
<input type="hidden" name="object_city" value="{{ i.city }}">
<input type="hidden" name="object_state" value="{{ i.state }}">
<input type="hidden" name="object_pin" value="{{ i.pin }}">
<input class="btn btn-success mx-2" name="form_approved" type="submit" value="Approve">
<input type="hidden" name="object_id" value="{{ i.id }}">
<input class="btn btn-danger mx-2" name="form_rejected" type="submit" value="Reject"> <!--Added attribute name="form_rejected"-->
OUTPUT после вывода на печать fname и pin:
went in approve
<QuerySet [('snaTYE',)]> <QuerySet [(939393,)]>
когда я печатаю fname только для проверки, он дает мне набор запросов, который не может быть вставлен, так как же вставить следующее в утвержденную базу данных или как получить только значение в наборе запросов.