I created a django project. It contains a model class with a "type" attribute. I think that "type" is the most appropriate term to describe that field, because it defines the kind of the entry.
class Vehicle(models.Model): TYPE = ( (u'car', u'Car'), (u'motorcycle', u'Motorcycle'), (u'airplane', u'Airplane'), ) type = models.CharField(max_length=100, choices=TYPE)
I do not like "kind" or "category" that much because they are not as generic as "type".
Assignment to reserved built-in symbol: type
Fields in Django are the data types to store a particular type of data. For example, to store an integer, IntegerField would be used. These fields have in-built validation for a particular data type, that is you can not store “abc” in an IntegerField. Similarly, for other fields.
To answer your question, with the new migration introduced in Django 1.7, in order to add a new field to a model you can simply add that field to your model and initialize migrations with ./manage.py makemigrations and then run ./manage.py migrate and the new field will be added to your DB.
How to use required in Django Form field? required is often used to make the field optional that is the user would no longer be required to enter the data into that field and it will still be accepted.
_ in Django is a convention that is used for localizing texts. It is an alias for ugettext_lazy.
I disagree with the other answers. There's no need to change this.
In my opinion, there is little risk of confusion, as you will never access the attribute except via an instance. my_vehicle.type
is not easy to confuse with (eg) type(my_vehicle)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With