How do i programmatically create a model that has an imagefield and fields to capture width and height in Django -


मेरे पास एक फोटो मॉडल है जो इस तरह दिखता है

  क्लास फोटो (models.Model) : title = models.CharField (MAX_LENGTH = 100, खाली = सच) चौड़ाई = models.IntegerField () ऊंचाई = models.IntegerField () छवि = models.ImageField (upload_to = upload_to_callable, width_field = "चौड़ाई", height_field = "ऊंचाई" ) content_type = models.ForeignKey (ContentType) object_id = models.PositiveIntegerField () content_object = generic.GenericForeignKey () create_date = models.DateTimeField (auto_now_add = सच) MODIFIED_DATE = models.DateTimeField (auto_now = सच) साइट = models.ForeignKey (साइट )   

अपने एक परीक्षण में मुझे इस मॉडल को प्रोग्राम बनाने की आवश्यकता है I यह मैं क्या कर रहा हूँ है

  डीईएफ़ _create_random_image (स्वयं): आयात छवि, ImageDraw img = Image.new ( "आरजीबी", (300,300), "#FFFFFF") आकर्षित = ImageDraw.Draw (आईएमजी) आर, जी, बी = प्रिंट (0,255), प्रिंट (0, 255), प्रिंट (0,255) डॉ = (प्रिंट (0, 255) -आर) / 300 डीजी = (प्रिंट (0, 255) - g) / 300 डीबी = (प्रिंट (0, 255) - बी) / 300 के लिए श्रेणी में (300): r, g, b = r + dr, g + dg, b + db draw.line ((i, 0, i, 300), भर = (int (r), int (g) ), पूर्णांक (ख))) tmpfilename = "/tmp/test36052.png" img.save (tmpfilename, "पीएनजी") च = फ़ाइल (tmpfilename) वापसी च डीईएफ़ testHomePageImage (स्वयं): tmpfile = self._create_random_image () तस्वीर = Photo.objects.create (छवि = tmpfile, title = site1_home_page.title, साइट = self.site1, content_object = site1_home_page)   

मैं निम्न त्रुटि

AttributeError:? 'फ़ाइल' वस्तु वहाँ एक आंतरिक Django उद्देश्य यह है कि फ़ाइल उद्देश्य यह है कि मैं उपयोग कर सकते हैं प्रदान करता है कोई विशेषता 'चौड़ाई'

है

सीधे f की बजाय ImageFile (f) लौटने का प्रयास करें ImageFile में है django.core.files.images.ImageFile । मेरे सिर के ऊपर से, मुझे लगता है कि ऐसा करेंगे।

संपादित करें: सही टाइपो, इसलिए यह सही है।

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -