1

I have a question list for a questionnaire which are stored in database but some questions has to be modified by certain parameters.

For example, if someone selects an employer name from previous page, some questions should have employer's name "Do you like to work for ........ company ?".

One solution might be savinf question like "Do you like to work for {0}" and formatting it but I am not sure how I can implement it with python.

But how can I detect which questions need to be modified ?

Is there any easy way to do it in django ?

Thanks

1 Answer 1

1

The most flexible way - is to create custom template filter. If string needs formatting, it will do that, if it doesn't - just output it.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks I got it but could you give me how can I detect if string needs to be modified or not ? Should I put flag in database level or python has some kind of function ?
@brsbilgic There are a lot of ways. You can store strings as 'Do you like to work for %s'. Then in your filter you try to format it (with % operator). If you get TypeError, formatting isn't supported, just output string. Otherwise format string and output result.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.