This blog is a follow up of the last post Working with Django Form.
The problem has been solved shortly after the first post. I found out that the real view which renders the user.html
is another view called view.index
. So after I altered the index
view everything worked just fine.
Moreover, I managed to customize the default form. The default form is something like this:
As you can see, there`s a modelchoice field to select the user
which is the ForeignKey
field and a text input field for field text
. But obviously the typical tweet interface is comprised solely of an input field because the user
who has already logged in is the author of the tweet. Given the situation, in the view I changed how the POST
data is passed to the form:
instead of passing the whole package of POST
data to the form, only the text
field is passed and the user
field is filled with the key of request.user
so that the author of the tweet will always be the user who has already logged in.
In addition, I overrode the default error message and initialized the text
field:
Hooray! Now I`ve got something close to a timeline and the user can post their own tweets. Still, the timeline only has the user`s own tweets because he hasn`t followed anybody and that`s one of the many things I need to work on.
Apart from the basic function of a typical socialnetwork application, the layout of the website is currently a mess. I basically hardcoded every detail of the site using .css
which is a totally stupid thing to do. Using Bootstrap to decorate the site is another thing goes into my to-do-list.
To summarize, I, again, make two lists of what I got and what to do:
Achievements
- Basic authentication function
- A timeline which stores all the tweets from the user himself.
- Allowing user to post his own tweets.
Way to go
- Bootstraping my website.
- Follow function.