I have the following django model:
class SomeProfile(models.Model):
type = models.CharField(max_length=1)
Is using "type" as an attribute name considered a bad practice?
Here the attribute is not shadowing "type", so it's not the same question as this one
There's nothing wrong with it. It's not a member of python's reserved keywords.
However, naming a method type()
would probably be confusing...
General rule is: don't use names that are taken (e.g. type
, file
, int
, etc.) regardless of whether they're in a "reserved" keywords list or not (since python allows it, it's not really "reserved"). This is mainly important to avoid getting into trouble when you actually need to use the real object (without noticing that you overrode it locally).
If you really want to use one of those names, just append _
at the end (e.g. type_
).
In your case, since you're specifying type
as a class attribute, it should be considered safe since it can only be accessed through its class (self.type
or SomeProfile.type
).
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