Le 09/12/2014 09:09, Guillem Barba Domingo a écrit :
El 05/12/2014 16:50, "Christophe" <[email protected] <mailto:[email protected]>> va escriure: > > Le 05/12/2014 16:16, Sergi Almacellas Abellana a écrit : > >> El 05/12/14 a les 15:41, Christophe ha escrit: >>> >>> Hello, >>> >>> Is there a way to remove constrainte put by a "required" clause ? >>> >>> In details, I have a field that have a constrainte put by the "required" >>> clause and i want to remove this constainte by overload of the class. >>> it-is possible ? >>> >> >> Yes, it's possible. You have to do the following things. >> >> 1. Update fields definition to set required to false. >> 2. Drop the not null constraint on the database. >> >> >> BTW: Can you tell us which is the field you want to remove the >> constraint? This will help us to prevent having to much constraints on >> base modules. >> > > I have made (1) for (2) i try with __register__ method but it don't work (or i have made a mistake) > > @classmethod > def __register__(cls, module_name): > super(Article, cls).__register__(module_name) > TableHandler = backend.get('TableHandler') > cursor = Transaction().cursor > table = TableHandler(cursor, cls, module_name) > table.not_null_action('content', action='remove') Have you set the required flag of field to False? It must to be set in __setup__() method
No, I thought to overload the field by removing the flag 'required' was sufficient ...
> For BTW : I try to remove constrainte from 'content' field because in my overload this field is not necessary (it is replaced by another). > > PS : I also view the Cedric response and what I want to do is perhaps not be possible. It could be done, but it is in the "good practices" to don't do it... But sometimes it is the way. In you example, it seems "content" is not strictly required. The main module should remove this flag and, provably, protect some parts of the code that asumes this field is not empty... Or you have tp be careful with the code you use from "parent module" to don't get an error because "content" is empty. You say that you replaced "content" field for another. Which kind of field? Why don't use "content"?
As I said in an issue on the github of nereid_cms (# 69), I think that writing an article with multimedia content in rst or markdown is complicated for a non-programmer, so I test an alternative.
I'm thinking if it makes sense to fill "content" field in "create" method no avoid databases not null error.
That's right, so I override the create method to do that, and now the original question is solved for me, but we can continue the thread for a better solution.
Regards -- Christophe http://adiczion.com
