django - 使用 Django 函数在数据库中添加一个字段
问题描述
这是我的模型课:
class complete_taxi_driver_account(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
STATUS_CHOICES = (('woman', 'Woman'), ('man', 'Man'),)
first_name = models.CharField(max_length=40)
last_name = models.CharField(max_length=40)
phone_number = models.CharField(max_length=11)
life_place = models.CharField(max_length=120)
birth_date = models.DateTimeField(null=False, blank=False)
gender = models.CharField(max_length=25, choices=STATUS_CHOICES, default='man')
number_plates = models.CharField(max_length=8)
national_code = models.CharField(max_length=10)
car_number = models.CharField(max_length=50)
name_and_type_of_car = models.CharField(max_length=50)
# Check if this car is taxi , this field will change to True else False
confirmation = models.BooleanField(default=False)
# If the taxi app starts, this section will change True, meaning the taxi is ready to pick up passengers
online = models.BooleanField(default=False)
#I do not know what to do here to add these two fields to the database when this function is called
def location(self):
# Location of the taxi
lat = models.DecimalField(max_digits=20, decimal_places=10)
lng = models.DecimalField(max_digits=20, decimal_places=10)
我想在模型类中有一个函数,当被调用时,它会在数据库中创建两个字段并填充它们,然后通过调用它来更新它们。我怎样才能做到这一点?
解决方案
推荐阅读
- sql - 用 SQL 中的平均值更新列
- python - 使用多个浏览器实例运行多线程 Selenium 自动化
- javascript - vue-router:为带有分页的过滤页面定义漂亮的 URL
- java - 列表视图上的搜索过滤器在单击时返回错误结果
- regex - 如何编写识别特定字母和最少数字的正则表达式
- node.js - 如何解决 npm run build 137 错误?已经设置了10gb
- react-native - 嵌套的 FlatList Carousel 错误:scrollToIndex 超出范围
- python - 具有非方形输入图像的 U-net
- java - 在超类中创建子类的实例
- swiftui - 删除在视图中的列表项上创建的空间 - SwiftUI