Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Is there any easy way (like a widget) to filter the input of a binary field?

形象
odoo
形象
丢弃
1 答案
0
形象
odoo
最佳答案

Hi,

I'm with the same problem and don't find a solution as simple as the one you mention. But there is a solution as i think simple enough : use the api.constrains. Here is my modus operandi:


1) I save the file's name

My model:

files = fields.Binary(string="Download Zip")
filename = fields.Char()

My view:

<field name="filename" invisible="1" />
<field name="files" filename="filename" />


2) I use the api.constrains to verify the extension

@api.one
@api.constrains('filename')
def _check_filename(self):
    if self.files:
        if not self.filename:
	    raise exceptions.ValidationError(_("There is no file"))
	else:
	    # Check the file's extension
	    tmp = self.filename.split('.')
	    ext = tmp[len(tmp)-1]
	    if ext != 'zip':
	        raise exceptions.ValidationError(_("The file must be a zip file"))


I know, it's not a very beautiful way to do it but it's an alternative solution to your problem.

Hope that help you.

1 备注
形象
丢弃
形象
odoo
-

Yes nice ....post its working...