Django中ImageField的使用


http://blog.csdn.net/u013690521/article/details/38777213

 

from django.db import models
from django.contrib import admin

# Create your models here.
class AdminUser(models.Model):
    loginname = models.CharField(max_length=64, unique=True, db_index=True)
    fullname = models.CharField(max_length=64)
    email = models.EmailField(max_length=64)
    password = models.CharField(max_length=64)
    url_height = models.PositiveIntegerField(default=75)
    url_width = models.PositiveIntegerField(default=75)
    admin_icon = models.ImageField(upload_to="icons", height_field='url_height', width_field='url_width')

admin.site.register(AdminUser)

其中ImageFiled的兩個參數height_field和width_field指定的是兩個字段,它們的作用是自動填充字段

也就是說當上傳圖片后,它就會自動獲取圖片的高和寬,並存入url_height和url_width字段


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM