1. 程式人生 > >實際專案的實現2

實際專案的實現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)

這樣車輛模組算是完成了