如何从其他应用程序添加新字段';在Django和Python中将s models.py转换为html
我想换个场地 我有预订应用程序的email.html和订单应用程序的order_detail.html。 这两个文件在页面底部都有一个单词“托儿所信息” 我想在这两个html文件的单词“托儿所信息”下使用service app中的托儿所字段 我写了命令,但没有出现。另一个类似order.shippingAddress1的可能会出现。 我怎样才能像其他人一样出现在托儿所 我的关系应用程序名称是预订、订单和服务 这是预订应用程序模板的email.html如何从其他应用程序添加新字段';在Django和Python中将s models.py转换为html,python,django,Python,Django,我想换个场地 我有预订应用程序的email.html和订单应用程序的order_detail.html。 这两个文件在页面底部都有一个单词“托儿所信息” 我想在这两个html文件的单词“托儿所信息”下使用service app中的托儿所字段 我写了命令,但没有出现。另一个类似order.shippingAddress1的可能会出现。 我怎样才能像其他人一样出现在托儿所 我的关系应用程序名称是预订、订单和服务 这是预订应用程序模板的email.html <!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Reservation #{{ transaction.id }} - TS</title>
<style>
table {
width: 60%;
margin: 0 auto;
border-collapse: collapse;
}
table tr td {
border: 1px solid #c1c1c1;
}
p {
padding-right: 50px;
padding-left: 50px;
}
</style>
</head>
<body>
<center>
<h1>Thanks for reserve with us</h1>
<p>This email is to confirm that you have reserved on the TS.<br>Please make sure that all the details of your order are correct.</p>
</center>
<br>
<table>
<tr>
<td valign="top" colspan="2" style="width: 50%;">
<b>Your Address:</b><br>
{{ transaction.billingName }}<br>
{{ transaction.billingAddress1 }}<br>
{{ transaction.billingCity }}<br>
{{ transaction.billingPostcode }}<br>
{{ transaction.billingCountry }}<br>
</td>
<td valign="top" colspan="2" style="width: 50%;">
<b>Reservation: </b>#{{ transaction.id }}<br>
<b>Date: </b>{{ transaction.created|date:"d M Y"}}
</td>
</tr>
<tr>
<td colspan="3" style="text-align: right;"><b>Total</b></td>
<td>${{ transaction.total }}</td>
</tr>
<tr>
<td colspan="3" style="text-align: right;"><b>Total paid</b></td>
<td>${{ transaction.total }}</td>
</tr>
<tr>
<td valign="top" colspan="2" style="width: 50%;">
<b>Nursery information:</b><br>
{{ transaction.nursery }}<br>
{{ transaction.shippingAddress1 }}<br>
{{ transaction.shippingCity }}<br>
{{ transaction.shippingPostcode }}<br>
{{ transaction.shippingCountry }}<br>
</td>
<td valign="top" colspan="2" style="width: 50%;">
<b>Payment details:</b><br>
${{ transaction.total }} was paid successfully via Stripe.
</td>
</tr>
</table>
<center>
<br>
<p>If you are a registered customer and want to check your order history, please <a href="http://127.0.0.1:8000/account/login/">sign in</a>.<br>Otherwise <a href="http://127.0.0.1:8000/account/create/">sign up</a> to create a new account with us.</p>
</center>
</body>
</html>
from django.shortcuts import render, redirect, get_object_or_404
from service.models import Nursery
from .models import Reservation, ReservationItem
from django.core.exceptions import ObjectDoesNotExist
import stripe
from django.conf import settings
from order.models import Order, OrderItem
from django.template.loader import get_template
from django.core.mail import EmailMessage
def _reservation_id(request):
reservation = request.session.session_key
if not reservation:
reservation = request.session.create()
return reservation
def add_reservation(request, nursery_id):
nursery = Nursery.objects.get(id=nursery_id)
try:
reservation = Reservation.objects.get(reservation_id=_reservation_id(request))
except Reservation.DoesNotExist:
reservation = Reservation.objects.create(
reservation_id = _reservation_id(request)
)
reservation.save()
try:
reservation_item = ReservationItem.objects.get(nursery=nursery, reservation=reservation)
if reservation_item.quantity < reservation_item.nursery.stock:
reservation_item.quantity += 1
reservation_item.save()
except ReservationItem.DoesNotExist:
reservation_item = ReservationItem.objects.create(
nursery = nursery,
quantity = 1,
reservation = reservation
)
reservation_item.save()
return redirect('reservation:reservation_detail')
def reservation_detail(request, total=0, counter=0, cart_items = None):
try:
reservation = Reservation.objects.get(reservation_id=_reservation_id(request))
reservation_items = ReservationItem.objects.filter(reservation=reservation, active=True)
for reservation_item in reservation_items:
total += (reservation_item.nursery.price * reservation_item.quantity)
counter += reservation_item.quantity
except ObjectDoesNotExist:
pass
stripe.api_key = settings.STRIPE_SECRET_KEY
stripe_total = int(total * 100)
description = 'Travel Sitter - Reserve'
data_key = settings.STRIPE_PUBLISHABLE_KEY
if request.method == 'POST':
# print(request.POST)
try:
token = request.POST['stripeToken']
email = request.POST['stripeEmail']
billingName = request.POST['stripeBillingName']
billingAddress1 = request.POST['stripeBillingAddressLine1']
billingcity = request.POST['stripeBillingAddressCity']
billingPostcode = request.POST['stripeBillingAddressZip']
billingCountry = request.POST['stripeBillingAddressCountryCode']
shippingName = request.POST['stripeShippingName']
shippingAddress1 = request.POST['stripeShippingAddressLine1']
shippingcity = request.POST['stripeShippingAddressCity']
shippingPostcode = request.POST['stripeShippingAddressZip']
shippingCountry = request.POST['stripeShippingAddressCountryCode']
customer = stripe.Customer.create(
email=email,
source = token
)
charge = stripe.Charge.create(
amount=stripe_total,
currency="usd",
description=description,
customer=customer.id
)
try:
order_details = Order.objects.create(
token = token,
total = total,
emailAddress = email,
billingName = billingName,
billingAddress1 = billingAddress1,
billingCity = billingcity,
billingPostcode = billingPostcode,
billingCountry = billingCountry,
shippingName = shippingName,
shippingAddress1 = shippingAddress1,
shippingCity = shippingcity,
shippingPostcode = shippingPostcode,
shippingCountry = shippingCountry
)
order_details.save()
for order_item in reservation_items:
oi = OrderItem.objects.create(
nursery = order_item.nursery.name,
quantity = order_item.quantity,
price = order_item.nursery.price,
order = order_details
)
oi.save()
nurseries = Nursery.objects.get(id=order_item.nursery.id)
nurseries.stock = int(order_item.nursery.stock - order_item.quantity)
nurseries.save()
order_item.delete()
print('The Reservation has been created')
try:
sendEmail(order_details.id)
print('The order email has been sent to the customer.')
except IOError as e:
return e
return redirect('order:thanks', order_details.id)
except ObjectDoesNotExist:
pass
except stripe.error.CardError as e:
return False,e
return render(request, 'reservation.html', dict(reservation_items = reservation_items, total = total, counter = counter, data_key = data_key, stripe_total = stripe_total, description = description))
def reservation_remove(request, nursery_id):
reservation = Reservation.objects.get(reservation_id=_reservation_id(request))
nursery = get_object_or_404(Nursery, id=nursery_id)
reservation_item = ReservationItem.objects.get(nursery=nursery, reservation=reservation)
if reservation_item.quantity > 1:
reservation_item.quantity -= 1
reservation_item.save()
else:
reservation_item.delete()
return redirect('reservation:reservation_detail')
def full_remove(request, nursery_id):
reservation = Reservation.objects.get(reservaton_id=_reservation_id(request))
nursery = get_object_or_404(Nursery, id=nursery_id)
reservation_item = ReservationItem.objects.get(nursery=nursery, reservation=reservation)
reservation_item.delete()
return redirect('reservation:reservation_detail')
def sendEmail(order_id):
transaction = Order.objects.get(id=order_id)
order_items = OrderItem.objects.filter(order=transaction)
try:
subject = "Travel Sitter - Reservation #{}".format(transaction.id)
to = ['{}'.format(transaction.emailAddress)]
from_email = "orders@travelsitter.com"
order_information = {
'transaction' : transaction,
'order_items' : order_items
}
message = get_template('email/email.html').render(order_information)
msg = EmailMessage(subject, message, to=to, from_email=from_email)
msg.content_subtype = 'html'
msg.send()
except IOError as e:
return e
from django.db import models
from service.models import Nursery
class Reservation(models.Model):
reservation_id = models.CharField(max_length=250, blank=True)
date_added = models.DateField(auto_now_add=True)
class Meta:
db_table = 'Reservation'
ordering = ['date_added']
def __str__(self):
return self.reservation_id
class ReservationItem(models.Model):
nursery = models.ForeignKey(Nursery, on_delete=models.CASCADE)
reservation = models.ForeignKey(Reservation, on_delete=models.CASCADE)
quantity = models.IntegerField()
active = models.BooleanField(default=True)
class Meta:
db_table = 'ReservationItem'
def sub_total(self):
return self.nursery.price * self.quantity
def __str__(self):
return self.nursery
这是预订应用程序的views.py
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Reservation #{{ transaction.id }} - TS</title>
<style>
table {
width: 60%;
margin: 0 auto;
border-collapse: collapse;
}
table tr td {
border: 1px solid #c1c1c1;
}
p {
padding-right: 50px;
padding-left: 50px;
}
</style>
</head>
<body>
<center>
<h1>Thanks for reserve with us</h1>
<p>This email is to confirm that you have reserved on the TS.<br>Please make sure that all the details of your order are correct.</p>
</center>
<br>
<table>
<tr>
<td valign="top" colspan="2" style="width: 50%;">
<b>Your Address:</b><br>
{{ transaction.billingName }}<br>
{{ transaction.billingAddress1 }}<br>
{{ transaction.billingCity }}<br>
{{ transaction.billingPostcode }}<br>
{{ transaction.billingCountry }}<br>
</td>
<td valign="top" colspan="2" style="width: 50%;">
<b>Reservation: </b>#{{ transaction.id }}<br>
<b>Date: </b>{{ transaction.created|date:"d M Y"}}
</td>
</tr>
<tr>
<td colspan="3" style="text-align: right;"><b>Total</b></td>
<td>${{ transaction.total }}</td>
</tr>
<tr>
<td colspan="3" style="text-align: right;"><b>Total paid</b></td>
<td>${{ transaction.total }}</td>
</tr>
<tr>
<td valign="top" colspan="2" style="width: 50%;">
<b>Nursery information:</b><br>
{{ transaction.nursery }}<br>
{{ transaction.shippingAddress1 }}<br>
{{ transaction.shippingCity }}<br>
{{ transaction.shippingPostcode }}<br>
{{ transaction.shippingCountry }}<br>
</td>
<td valign="top" colspan="2" style="width: 50%;">
<b>Payment details:</b><br>
${{ transaction.total }} was paid successfully via Stripe.
</td>
</tr>
</table>
<center>
<br>
<p>If you are a registered customer and want to check your order history, please <a href="http://127.0.0.1:8000/account/login/">sign in</a>.<br>Otherwise <a href="http://127.0.0.1:8000/account/create/">sign up</a> to create a new account with us.</p>
</center>
</body>
</html>
from django.shortcuts import render, redirect, get_object_or_404
from service.models import Nursery
from .models import Reservation, ReservationItem
from django.core.exceptions import ObjectDoesNotExist
import stripe
from django.conf import settings
from order.models import Order, OrderItem
from django.template.loader import get_template
from django.core.mail import EmailMessage
def _reservation_id(request):
reservation = request.session.session_key
if not reservation:
reservation = request.session.create()
return reservation
def add_reservation(request, nursery_id):
nursery = Nursery.objects.get(id=nursery_id)
try:
reservation = Reservation.objects.get(reservation_id=_reservation_id(request))
except Reservation.DoesNotExist:
reservation = Reservation.objects.create(
reservation_id = _reservation_id(request)
)
reservation.save()
try:
reservation_item = ReservationItem.objects.get(nursery=nursery, reservation=reservation)
if reservation_item.quantity < reservation_item.nursery.stock:
reservation_item.quantity += 1
reservation_item.save()
except ReservationItem.DoesNotExist:
reservation_item = ReservationItem.objects.create(
nursery = nursery,
quantity = 1,
reservation = reservation
)
reservation_item.save()
return redirect('reservation:reservation_detail')
def reservation_detail(request, total=0, counter=0, cart_items = None):
try:
reservation = Reservation.objects.get(reservation_id=_reservation_id(request))
reservation_items = ReservationItem.objects.filter(reservation=reservation, active=True)
for reservation_item in reservation_items:
total += (reservation_item.nursery.price * reservation_item.quantity)
counter += reservation_item.quantity
except ObjectDoesNotExist:
pass
stripe.api_key = settings.STRIPE_SECRET_KEY
stripe_total = int(total * 100)
description = 'Travel Sitter - Reserve'
data_key = settings.STRIPE_PUBLISHABLE_KEY
if request.method == 'POST':
# print(request.POST)
try:
token = request.POST['stripeToken']
email = request.POST['stripeEmail']
billingName = request.POST['stripeBillingName']
billingAddress1 = request.POST['stripeBillingAddressLine1']
billingcity = request.POST['stripeBillingAddressCity']
billingPostcode = request.POST['stripeBillingAddressZip']
billingCountry = request.POST['stripeBillingAddressCountryCode']
shippingName = request.POST['stripeShippingName']
shippingAddress1 = request.POST['stripeShippingAddressLine1']
shippingcity = request.POST['stripeShippingAddressCity']
shippingPostcode = request.POST['stripeShippingAddressZip']
shippingCountry = request.POST['stripeShippingAddressCountryCode']
customer = stripe.Customer.create(
email=email,
source = token
)
charge = stripe.Charge.create(
amount=stripe_total,
currency="usd",
description=description,
customer=customer.id
)
try:
order_details = Order.objects.create(
token = token,
total = total,
emailAddress = email,
billingName = billingName,
billingAddress1 = billingAddress1,
billingCity = billingcity,
billingPostcode = billingPostcode,
billingCountry = billingCountry,
shippingName = shippingName,
shippingAddress1 = shippingAddress1,
shippingCity = shippingcity,
shippingPostcode = shippingPostcode,
shippingCountry = shippingCountry
)
order_details.save()
for order_item in reservation_items:
oi = OrderItem.objects.create(
nursery = order_item.nursery.name,
quantity = order_item.quantity,
price = order_item.nursery.price,
order = order_details
)
oi.save()
nurseries = Nursery.objects.get(id=order_item.nursery.id)
nurseries.stock = int(order_item.nursery.stock - order_item.quantity)
nurseries.save()
order_item.delete()
print('The Reservation has been created')
try:
sendEmail(order_details.id)
print('The order email has been sent to the customer.')
except IOError as e:
return e
return redirect('order:thanks', order_details.id)
except ObjectDoesNotExist:
pass
except stripe.error.CardError as e:
return False,e
return render(request, 'reservation.html', dict(reservation_items = reservation_items, total = total, counter = counter, data_key = data_key, stripe_total = stripe_total, description = description))
def reservation_remove(request, nursery_id):
reservation = Reservation.objects.get(reservation_id=_reservation_id(request))
nursery = get_object_or_404(Nursery, id=nursery_id)
reservation_item = ReservationItem.objects.get(nursery=nursery, reservation=reservation)
if reservation_item.quantity > 1:
reservation_item.quantity -= 1
reservation_item.save()
else:
reservation_item.delete()
return redirect('reservation:reservation_detail')
def full_remove(request, nursery_id):
reservation = Reservation.objects.get(reservaton_id=_reservation_id(request))
nursery = get_object_or_404(Nursery, id=nursery_id)
reservation_item = ReservationItem.objects.get(nursery=nursery, reservation=reservation)
reservation_item.delete()
return redirect('reservation:reservation_detail')
def sendEmail(order_id):
transaction = Order.objects.get(id=order_id)
order_items = OrderItem.objects.filter(order=transaction)
try:
subject = "Travel Sitter - Reservation #{}".format(transaction.id)
to = ['{}'.format(transaction.emailAddress)]
from_email = "orders@travelsitter.com"
order_information = {
'transaction' : transaction,
'order_items' : order_items
}
message = get_template('email/email.html').render(order_information)
msg = EmailMessage(subject, message, to=to, from_email=from_email)
msg.content_subtype = 'html'
msg.send()
except IOError as e:
return e
from django.db import models
from service.models import Nursery
class Reservation(models.Model):
reservation_id = models.CharField(max_length=250, blank=True)
date_added = models.DateField(auto_now_add=True)
class Meta:
db_table = 'Reservation'
ordering = ['date_added']
def __str__(self):
return self.reservation_id
class ReservationItem(models.Model):
nursery = models.ForeignKey(Nursery, on_delete=models.CASCADE)
reservation = models.ForeignKey(Reservation, on_delete=models.CASCADE)
quantity = models.IntegerField()
active = models.BooleanField(default=True)
class Meta:
db_table = 'ReservationItem'
def sub_total(self):
return self.nursery.price * self.quantity
def __str__(self):
return self.nursery
这是预订应用程序的models.py
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Reservation #{{ transaction.id }} - TS</title>
<style>
table {
width: 60%;
margin: 0 auto;
border-collapse: collapse;
}
table tr td {
border: 1px solid #c1c1c1;
}
p {
padding-right: 50px;
padding-left: 50px;
}
</style>
</head>
<body>
<center>
<h1>Thanks for reserve with us</h1>
<p>This email is to confirm that you have reserved on the TS.<br>Please make sure that all the details of your order are correct.</p>
</center>
<br>
<table>
<tr>
<td valign="top" colspan="2" style="width: 50%;">
<b>Your Address:</b><br>
{{ transaction.billingName }}<br>
{{ transaction.billingAddress1 }}<br>
{{ transaction.billingCity }}<br>
{{ transaction.billingPostcode }}<br>
{{ transaction.billingCountry }}<br>
</td>
<td valign="top" colspan="2" style="width: 50%;">
<b>Reservation: </b>#{{ transaction.id }}<br>
<b>Date: </b>{{ transaction.created|date:"d M Y"}}
</td>
</tr>
<tr>
<td colspan="3" style="text-align: right;"><b>Total</b></td>
<td>${{ transaction.total }}</td>
</tr>
<tr>
<td colspan="3" style="text-align: right;"><b>Total paid</b></td>
<td>${{ transaction.total }}</td>
</tr>
<tr>
<td valign="top" colspan="2" style="width: 50%;">
<b>Nursery information:</b><br>
{{ transaction.nursery }}<br>
{{ transaction.shippingAddress1 }}<br>
{{ transaction.shippingCity }}<br>
{{ transaction.shippingPostcode }}<br>
{{ transaction.shippingCountry }}<br>
</td>
<td valign="top" colspan="2" style="width: 50%;">
<b>Payment details:</b><br>
${{ transaction.total }} was paid successfully via Stripe.
</td>
</tr>
</table>
<center>
<br>
<p>If you are a registered customer and want to check your order history, please <a href="http://127.0.0.1:8000/account/login/">sign in</a>.<br>Otherwise <a href="http://127.0.0.1:8000/account/create/">sign up</a> to create a new account with us.</p>
</center>
</body>
</html>
from django.shortcuts import render, redirect, get_object_or_404
from service.models import Nursery
from .models import Reservation, ReservationItem
from django.core.exceptions import ObjectDoesNotExist
import stripe
from django.conf import settings
from order.models import Order, OrderItem
from django.template.loader import get_template
from django.core.mail import EmailMessage
def _reservation_id(request):
reservation = request.session.session_key
if not reservation:
reservation = request.session.create()
return reservation
def add_reservation(request, nursery_id):
nursery = Nursery.objects.get(id=nursery_id)
try:
reservation = Reservation.objects.get(reservation_id=_reservation_id(request))
except Reservation.DoesNotExist:
reservation = Reservation.objects.create(
reservation_id = _reservation_id(request)
)
reservation.save()
try:
reservation_item = ReservationItem.objects.get(nursery=nursery, reservation=reservation)
if reservation_item.quantity < reservation_item.nursery.stock:
reservation_item.quantity += 1
reservation_item.save()
except ReservationItem.DoesNotExist:
reservation_item = ReservationItem.objects.create(
nursery = nursery,
quantity = 1,
reservation = reservation
)
reservation_item.save()
return redirect('reservation:reservation_detail')
def reservation_detail(request, total=0, counter=0, cart_items = None):
try:
reservation = Reservation.objects.get(reservation_id=_reservation_id(request))
reservation_items = ReservationItem.objects.filter(reservation=reservation, active=True)
for reservation_item in reservation_items:
total += (reservation_item.nursery.price * reservation_item.quantity)
counter += reservation_item.quantity
except ObjectDoesNotExist:
pass
stripe.api_key = settings.STRIPE_SECRET_KEY
stripe_total = int(total * 100)
description = 'Travel Sitter - Reserve'
data_key = settings.STRIPE_PUBLISHABLE_KEY
if request.method == 'POST':
# print(request.POST)
try:
token = request.POST['stripeToken']
email = request.POST['stripeEmail']
billingName = request.POST['stripeBillingName']
billingAddress1 = request.POST['stripeBillingAddressLine1']
billingcity = request.POST['stripeBillingAddressCity']
billingPostcode = request.POST['stripeBillingAddressZip']
billingCountry = request.POST['stripeBillingAddressCountryCode']
shippingName = request.POST['stripeShippingName']
shippingAddress1 = request.POST['stripeShippingAddressLine1']
shippingcity = request.POST['stripeShippingAddressCity']
shippingPostcode = request.POST['stripeShippingAddressZip']
shippingCountry = request.POST['stripeShippingAddressCountryCode']
customer = stripe.Customer.create(
email=email,
source = token
)
charge = stripe.Charge.create(
amount=stripe_total,
currency="usd",
description=description,
customer=customer.id
)
try:
order_details = Order.objects.create(
token = token,
total = total,
emailAddress = email,
billingName = billingName,
billingAddress1 = billingAddress1,
billingCity = billingcity,
billingPostcode = billingPostcode,
billingCountry = billingCountry,
shippingName = shippingName,
shippingAddress1 = shippingAddress1,
shippingCity = shippingcity,
shippingPostcode = shippingPostcode,
shippingCountry = shippingCountry
)
order_details.save()
for order_item in reservation_items:
oi = OrderItem.objects.create(
nursery = order_item.nursery.name,
quantity = order_item.quantity,
price = order_item.nursery.price,
order = order_details
)
oi.save()
nurseries = Nursery.objects.get(id=order_item.nursery.id)
nurseries.stock = int(order_item.nursery.stock - order_item.quantity)
nurseries.save()
order_item.delete()
print('The Reservation has been created')
try:
sendEmail(order_details.id)
print('The order email has been sent to the customer.')
except IOError as e:
return e
return redirect('order:thanks', order_details.id)
except ObjectDoesNotExist:
pass
except stripe.error.CardError as e:
return False,e
return render(request, 'reservation.html', dict(reservation_items = reservation_items, total = total, counter = counter, data_key = data_key, stripe_total = stripe_total, description = description))
def reservation_remove(request, nursery_id):
reservation = Reservation.objects.get(reservation_id=_reservation_id(request))
nursery = get_object_or_404(Nursery, id=nursery_id)
reservation_item = ReservationItem.objects.get(nursery=nursery, reservation=reservation)
if reservation_item.quantity > 1:
reservation_item.quantity -= 1
reservation_item.save()
else:
reservation_item.delete()
return redirect('reservation:reservation_detail')
def full_remove(request, nursery_id):
reservation = Reservation.objects.get(reservaton_id=_reservation_id(request))
nursery = get_object_or_404(Nursery, id=nursery_id)
reservation_item = ReservationItem.objects.get(nursery=nursery, reservation=reservation)
reservation_item.delete()
return redirect('reservation:reservation_detail')
def sendEmail(order_id):
transaction = Order.objects.get(id=order_id)
order_items = OrderItem.objects.filter(order=transaction)
try:
subject = "Travel Sitter - Reservation #{}".format(transaction.id)
to = ['{}'.format(transaction.emailAddress)]
from_email = "orders@travelsitter.com"
order_information = {
'transaction' : transaction,
'order_items' : order_items
}
message = get_template('email/email.html').render(order_information)
msg = EmailMessage(subject, message, to=to, from_email=from_email)
msg.content_subtype = 'html'
msg.send()
except IOError as e:
return e
from django.db import models
from service.models import Nursery
class Reservation(models.Model):
reservation_id = models.CharField(max_length=250, blank=True)
date_added = models.DateField(auto_now_add=True)
class Meta:
db_table = 'Reservation'
ordering = ['date_added']
def __str__(self):
return self.reservation_id
class ReservationItem(models.Model):
nursery = models.ForeignKey(Nursery, on_delete=models.CASCADE)
reservation = models.ForeignKey(Reservation, on_delete=models.CASCADE)
quantity = models.IntegerField()
active = models.BooleanField(default=True)
class Meta:
db_table = 'ReservationItem'
def sub_total(self):
return self.nursery.price * self.quantity
def __str__(self):
return self.nursery
我每次都很感激你的好意。
如果我必须出示其他文件,请教我。因为托儿所是订单模型课中的外键。这意味着托儿所模型班与顺序班有一对多的关系。为了访问html文件中的托儿所模型类属性,您可以使用order对象和托儿所键进行访问
For Example:
order.nursery.name: This would return the name of Nursery.
以类似的方式,您可以访问html文件中的所有其他托儿所属性。我更改了我的email.htmlNursery信息:
{{transaction.turry.description}
并且更改了我的订单{u detail.htmlNursery信息:
{order.turry.desctiption}
描述是托儿所模型字段的一个字段。但仍然无法反映此更改。我根据上面的建议进行了更改,但无法显示此内容。在html渲染时,您看到的输出是什么?另外,在您尝试获取属性时,请确保数据库中的托儿所Foreignkey不为null。如果上述答案对您的情况有帮助,请将其向上投票,以便其他人能够获得好处。