我是django的初学者。我阅读了REST API的文档。如何将我的模型详细信息发送到zapier,以及如何进行webhook和配置? 请帮我。当我的司机预订汽车时,如何将我的司机送到zapier并与zapier连接
模型
class Booking(models.Model):
class Meta():
db_table = "booking"
verbose_name = "Booking"
verbose_name_plural = "Bookings"
ordering = ['-booking_date']
booking_car_car = models.ForeignKey(
Car,
on_delete=models.CASCADE,
related_name='booking_car_car_key'
)
booking_customer_customer = models.ForeignKey(
Customer,
on_delete=models.CASCADE,
related_name='booking_customer_customer'
)
booking_start_date = models.DateField(
blank=False,
null=False
)
booking_end_date = models.DateField(
blank=False,
null=False
)
booking_total_price = models.IntegerField(
blank=False,
null=False
)
booking_approved = models.NullBooleanField(
blank=True,
null=True
)
booking_date = models.DateTimeField(
auto_now_add=True,
blank=False,
null=False
)
def __str__(self):
return self.booking_customer_customer.customer_firstname
答案 0 :(得分:1)
我以前没有使用Zapier的经验,但是,您可以通过覆盖模型的HTTP POST
方法来向zapier网址发送save()
请求。
import requests
class SampleModel(models.Model):
# your fields
def save(self, *args,**kwargs):
if not self.pk: #send webhook on "EVERY OBJECT CREATION"
webhook_data = your data to be sent to zapier
requests.post(url=zapier_url,
data=webhook_data)