I'm trying to make a code-name(i.e: Test Post will be TP-1, TP-2 ...) thing on Django. There is news model, and post model i got. When user create news title hence post's codename will be according it's news's title. For example the
news.title='Test News'
then assume that I created a first post and assign it in variable a
print a.codename
must return TN-1
Currently i can take News title by it's abbreviation in 2 or 3 letter and problem is how to add number after letters. And Posts are related to News by ForeignKey
therefore number should increase according news like shown below.
Test news
- TN-1
- TN-2
Foo news
- FN-1
- FN-3
- FN-4