Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python/Django: synonym for field "type" in database model (reserved built-in symbol)

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".

The problem

Assignment to reserved built-in symbol: type 
  1. This is a warning, so is that a problem?
  2. If yes, what choices do i have?
  3. Do you have a good alternative to the term "type"?
like image 486
Alp Avatar asked May 09 '12 12:05

Alp


People also ask

What does field type signifies in Django models?

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.

How do I add a field to an existing model in Django?

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.

What is required field in Django model?

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.

What does _() mean in Django?

_ in Django is a convention that is used for localizing texts. It is an alias for ugettext_lazy.


1 Answers

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).

like image 108
Daniel Roseman Avatar answered Sep 20 '22 19:09

Daniel Roseman