Ask Your Question

adding a new text field to question

asked 2012-06-12 14:54:34 -0500

kintali's avatar

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.,).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-06-12 15:00:20 -0500

Evgeny's avatar

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.

edit flag offensive delete link more


Thanks Evgeny.

kintali's avatar kintali  ( 2012-06-12 15:38:28 -0500 )edit

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  ( 2013-08-15 04:09:08 -0500 )edit

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  ( 2013-08-15 04:15:17 -0500 )edit

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  ( 2013-08-15 04:35:16 -0500 )edit

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  ( 2013-08-15 04:38:47 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2012-06-12 14:54:34 -0500

Seen: 638 times

Last updated: Jun 12 '12