Practice of Prefixing Field Names

Hi,

I would like to prefix all of my field names, either with a generec “fld_” or with something model specific like “pmt_” for a Payment, examples: “pmt_date”, “pmt_amount”. This would prevent clashing with such fields that I might want to name “type” or “date”. But I can see from documentation that it’s discouraged. Is it just convention? Is there a good way around this other than going to a thesaurus and coming up with goofy alternatives like “kind” instead of “type”?

Thanks,
Ben

Could you drop the link to where this is discouraged in the docs? Interesting question.

I was poking around trying to find similar questions and I found this: https://stackoverflow.com/questions/23719759/django-models-with-same-or-similar-fields

Using their inheritance solution you could do something like:

class Payment(models.Model):
    payment_amount = ....
    payment_date = ....

class ModelWithPayments(Payment):
    field = ...
    field2 = ..

This does not remove the prefix, however, it does seem to be more DRY instead of adding a prefixed field to all necessary models. I think this would be a good question to put on Stack Overflow- you will likely get a much better answer.

Since you asked I went looking and while I thought I had seen something in the past, now I can’t find anything specific about not adding prefixes to field names. But I also can’t find any examples of anyone doing so. Thanks for the stackoverflow link and suggestion

To my way of thinking, it is good to make a strict identification to fields that might be similar. Where I use this practice is for the ID field. Where some use the same name (ID) in all tables I generally add the table name or at least a portion of the table name to to the ID field.