Quantcast
Viewing latest article 29
Browse Latest Browse All 140

django how to change fields input according to related model field

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

    1. TN-1
    2. TN-2
  • Foo news

    1. FN-1
    2. FN-3
    3. FN-4

Viewing latest article 29
Browse Latest Browse All 140

Trending Articles