- edited description
Change reference type name
ref_type and task_type should probably be renamed to type for consistency with other models.
Comments (4)
-
reporter -
I agree with the consistency, but since `type` is a built-in in python, it would be better to avoid using that word. Sometimes people use `type_` or similar -- I don't like it much, but I can't think of a good alternative.
-
reporter Normally I'd avoid using `type` as well, but I think I'm okay with it in this particular situation.
In a situation like this you are only likely to use `type` qualified by the self namespace or as an object attribute e.g.
class MyModel(models.Model): type = models.CharField() def do_something(self): if self.type == "bar": print "baz" my_model = MyModel() my_model.type = "bar" my_model.do_something()
So you don't need to worry about clobbering the built in `type`
The main situation I can think of where you'd have to be careful is something like
class MyModel(models.Model): type = models.CharField() number = models.IntegerField() def __init__(self,type,name): self.type = type if type(number) == str: number = int(number) self.number = number my_model = MyModel("foo","100") #Throws a TypeError: 'str' object is not callable exception
But I think that is rare enough that we can safely ignore it rather than have to use `type_` all over the place.
Thoughts?
-
reporter - changed status to resolved
I've changed the 'ref_type' & 'task_type' fields to just be 'type' in the models in the reorg branch and I'm going to mark this as resolved for now.
Darcy, if you feel strongly enough that we shouldn't use 'type' here then please feel free to re-open this issue and we'll come up with a different solution.
- Log in to comment