Why does it not occur any error?
On a Model, you can define zero or more fields that have an equivalent in the database, but besides that, you can add zero or more functions, properties, attributes, etc. on the model as well.
You probably already did that somehow. For example:
class Symbol(models.Model):
market = models.CharField(
max_length=20,
null=True,
blank=True,
)
def __init__(self, *args, **kwargs):
super(Symbol, self).__init__(*args, **kwargs)
self.cache = {}
@property
def market3(self):
return self.market and self.market[:3]
After all those models are in fact Python objects, with some magic attached such that if you change an attribute and there is a field with the same name, then it corresponds to that field. But usually models also have some extra logic, and attributes to make them more intelligent, handle parts of a request at the model level, calculate properties that depend one one or more fields, etc.
By writing:
s.i_dont_know = 1
You attached an attribute to the s object with name 'i_dont_know' and value 1. Note however that this attribute is not persistent: if you save the object, and later reload it from the database, then all the extra data you attached to it, will be gone. Unless of course you define a setter that adds some extra logic.
.first()and.none()as well, since it is the relation is a queryset.