实际项目的实现2

前面对use_er做了设置,也就是用户模块,
接下来对车辆细节模块进行构造,同样是在cardetail1目录下的models.py中进行编写,

from django.db import models

# Create your models here.
class Carstyles(models.Model):
'''创建车辆类型'''
	name=models.CharField(max_length=10,verbose_name='车辆类型')
	image=models.ImageField(upload_to='type',verbose_name='车辆代表图片')
	class Meta:
	'''修改后端中carstyles的显示名称'''
		verbose_name='车辆类型'
		verbose_name_plural=verbose_name

class Brand(models.Model):
	name=models.CharField(max_length=10,verbose_name='车辆品牌')
	class Meta:
		verbose_name='车辆品牌'
		verbose_name_plural=verbose_name
		
class CarDetail(models.Model):
    status_choice=(
	    (0,'未上线'),(1,'已上线')
    )
    user=models.ForeignKey('use_er.UserInfo',verbose_name='车辆持有人')
    style=models.ForeignKey('Carstyles',verbose_name='车辆类型')
    logo=models.ForeignKey('Brand',verbose_name='车辆品牌')
	car_models=models.CharField(max_length=20,verbose_name='车辆型号')
	color=models.CharField(max_length=20,verbose_name='车辆颜色')
	age=models.CharField(max_length=10,verbose_name='车辆年龄')
	# '''之所以是字符串类型,是因为车龄为 一年以内,三年以内 =='''
	transmission_case = models.CharField(max_length=10, verbose_name='变速箱')
    mileage = models.DecimalField(max_digits=10,decimal_places=2,verbose_name='里程数')
    displacement = models.CharField(max_length=10, verbose_name='排量')
    emission_standard = models.IntegerField(max_length=5,verbose_name='排放标准g/km')
    Fuel_type = models.CharField(max_length=10, verbose_name='燃油类型')
    License_plate_location = models.CharField(max_length=10, verbose_name='车牌所在地')
    drive = models.CharField(max_length=10, verbose_name='驱动')
    country = models.CharField(max_length=10, verbose_name='国别')
    status = models.IntegerField(default=1,choices=status_choice,verbose_name='状态')
    class Meta:
        verbose_name='车辆明细'
        verbose_name_plural=verbose_name

class Image_detail(models.Model):
    path =  models.ImageField(upload_to='/detail_img',verbose_name='车辆细节图')
    index = models.IntegerField(verbose_name='顺序')
    car_detail = models.ForeignKey('Cardetail',verbose_name='车辆细节图')
    class Meta:
        verbose_name = '车辆图片细节'
        verbose_name_plural = verbose_name

class IndexBanner(models.Model):
    models.ImageField(upload_to='/banner',verbose_name='图片')
    index = models.IntegerField(verbose_name='展示顺序')

    class Meta:
        verbose_name = '首页轮播图'
        verbose_name_plural = verbose_name

这样车辆模块的数据表也算完成了,接下来在网站后台中展示出来,同样也要在admin中填写

from django.contrib import admin

# Register your models here.
from cardetail1.models import Cardetail,Carstyles,Brand,Image_detail,IndexBanner

admin.site.register(Cardetail)
admin.site.register(Carstyles)
admin.site.register(Brand)
admin.site.register(Image_detail)
admin.site.register(IndexBanner)

这样车辆模块算是完成了

你可能感兴趣的:(实际项目的实现2)