First time here? Check out the FAQ!
2

adding a new text field to question
 

I am planning to add a new (optional) text field (with a single line textbox and at most 200 characters) to "the question" in askbot code. Please point me to files that need to be changed and other required steps (like database migration etc.,).

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
kintali's avatar
141
kintali
asked 12 years ago

Comments

see more comments

1 Answer

2

To make things simpler, create a model related to thread via foreign key and maintain it in the separate app, and have migrations for that app separately. That way it will be much easier to maintain your version and avoid clashes in the migrations.

The question model is askbot.models.Thread. There is also model askbot.model.Post, which contains all comment, answer and question bodies. Thread holds the question title, tags and some more things.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 12 years ago
link

Comments

Thanks Evgeny.

kintali's avatar kintali (12 years ago)

Is there any painless way to link the related model to askbot.models.Thread, I'm trying to avoid hacking the source but I can't seem to be able to extend question functionality without doing so.

shano's avatar shano (11 years ago)

Maybe create a model and add Thread as foreign key with the related_name ? This way you won't need to modify any of the Askbot code.

Evgeny's avatar Evgeny (11 years ago)

That could work, but it would mean a many-to-one relationship in the wrong direction. I could potentially create a m2m relationship but that's not ideal. I'm adding locations as a form of required tag and anticipated this would need a new model attached to threads, I might look into seeing if I can work this feature into tags itself.

shano's avatar shano (11 years ago)

You can add one-to-one if you want or add a unique together constraint on ids or use ManyToMany. However I would not recommend M2M unless you really need it as database lookups will be less efficient. You could also just fork the code and add your field or add a field with migration from the additional app. If you just need one field, adding it directly will be the most efficient, but requires changes in the base schema.

Evgeny's avatar Evgeny (11 years ago)
see more comments