Django如何自动获取用户ID?

时间:2018-07-31 08:27:28

标签: django django-forms django-views

我是django的新手,如何在提交表单(例如)时获取客户模型的ID

john正在提交预订表格,我要在客户注册表格时自动让谁提交预订。意思是链接将发送给客户进行预订。在预订时,我想自动为预订初始化客户。表示约翰预定了汽车,并详细说明了他何时需要预订汽车。

模型

2

观看次数

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


class Customer(models.Model):
    first_name = models.CharField(max_length=64,null= False)
    last_name = models.CharField(max_length=64)
    customer_age = models.IntegerField(blank=True, null=True)
    last_name = models.CharField(blank=True, max_length=100)
    license_year = models.IntegerField(blank=False, null=False)
    tlc_number = models.IntegerField(blank=False ,null=False)
    contact_num =models.IntegerField(blank=False, null=False)
    contact_email = models.EmailField(blank =False)


    def __str__(self):
        return self.first_name

有人可以帮助我提供代码,因为我没有得到预订的客户。所有客户都在其中显示商品,我不希望该下拉菜单我希望自动选择

0 个答案:

没有答案
相关问题