Hi All,
Apologize if this question has been asked before. This is my first question
into this mailing list.
I am creating a custom field(MyCustomField) with a custom value
class(MyValue). I do have a deconstruct() method for my *field* class. And
I would like to have a default value of this field.
class MyModel(models.Model):
myValue = MyCustomField(default = MyValue(args))
But when I do the migration, error happens and I realized I need a
deconstruct() method(or @deconstructible) my *value* class. (https://docs.
djangoproject.com/en/1.10/topics/migrations/#custom-deconstruct-method) to
serialize the default value. There is no error after I do that. But my
question is,
Based on the guide, I am supposed to be able to write a custom field using
existing value class which I don't have access to the source. Quote below,
"In order to use the Hand class in our models, we *do not* have to change
this class at all. This is ideal, because it means you can easily write
model support for existing classes where you cannot change the source code."
from: https://docs.djangoproject.com/en/1.10/howto/custom-model-fields/
So is giving a deconstruct() method and probably a __eq__() method violate
this principle? I know I can subclass the existing class. But is it what I
supposed to do? I just want to make sure my understanding is correct and
what is the right design rule here?
Thanks
--
Qilin Qi
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CA%2BTBJyh6RyRPDOSPrqERnTtzAp94ONsjxYdoD1-4EEW0vf30YA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.