How can I use a SQL nextval function in a Django insert - Custom Model Field? -
I am trying to write a model field when the call is placed when inserting a model, then So far I have come up with a field that I override How do I get around the quoted value? I have this area for: I'm not sure what you're doing is the best Django practice, but here's how you can use. Also consider using SubfieldBase in Django 1.5 + See in Django & lt; 1.5 View nextval (" My_seq ") is something like the queries of the query DNS that arises:
app_table (A, B) values INSERT ("Some", next ("my_seq"));
get_db_prep_value and returns it to
nextval string when the object Is being inserted, but it gets quoted
class MyField (models.Field): def __init __ (self, * Argus, ** kwargs): self.obj = Any Super (MyField, Self) .__ init__ (* args, ** kwargs def contribution _to_class (self, cls, name): Super (MyField, Self) Contribution_sto- Class (CLS, name) setter (CLS, self name, self) DEF __get __ (self, oBJ, TP = none): If OBJE is none: Entitlement Entry (can only be accessed by 'example) self .obj = obj return obj .__ dic T __ [self.name] def __set __ (self, obj, value): obj .__ dict __ [self.value] = self.to_python (value) def db_type (self, connection): 'varchar (25)' def Get_db_prep_value (self, value, connection, ready = false): value = super (MyField, self) .get_db_prep_value (value, connection, ready) if self.obj is not there and nobody has .obj.id none: if Self.obj.flag: value = '("XXX" ||' my_seq ')' return value def to _python (self, value): ifinstance (value, six .string_types) or value none: return value Return smart_text (value) def get_prep_value (self, value): return self.to_python (value)
class MyField (models.Field, metaclass = models.SubfieldBase):
__ metaclass__ = model ShabfieldBase
Comments
Post a Comment