web applications - Working with accounts and user generated data in Django -
I have not received any documents or tutorials on this subject, no response has been received on the IRC channel, I think I am wrong I'm looking for cheese. Anyways, after searching for several hours after taking the help of SO, I will try to describe what I am doing after the example:
- I want to create a web application where the user is created (This part is clear
- After entering, the user will be able to store their favorite food
- When a user logs in, Will see the list and it ends up with them I can understand
I understand how the user can create a account and log in. But after that everything is blurry.
Users After logging in, suppose that it will be presented with the form that it can fill and save. How to recover user accumulated data from the database (i.e. favorite foods)?
These Things are I 'as I said I do not have any I have not been described in books, docs or tutorials, which I did.
I would appreciate it if you can tell me the right direction. I think I'm missing something here.
Basic content:
- For a foreign key in your model User
- Press the user field from the form
- Save the form with Commit = Falls, set the user to a certified user and save the model.
The rest can move you very straight from the tutorial.
For example:
.contrib.auth.models Import user class preferred (models.Model): user = models.ForeignKey (user) # other fields .. # Forms.py class FavoriteMealForm (forms.ModelForm): Category Meta: Model = FavoriteMalally Excluded = ('Users',) Favorites_males_view on # views.py@login_required def: Favorites_males = FavoriteMile.BigExtfileer (user = Requests) .user) ... if request. Method == 'POST': form = FavoriteMealForm (Request.POST) if form.is_valid (): favorites_melow = form.save (commit = False) favorite_meagle.asser = request.user favorites_melay save () ...
Comments
Post a Comment