Python Django Tutorial: Full-Featured Web App Part 10 - Create, Update, and Delete Posts

Corey Schafer · 383K views · 2018 · 53:15

Open on YouTube

Web developmentPython, Ruby & scripting languagestutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering or following along with Django CreateView and class-based view questions, such as setting the current user on a new object.

Recommended by 1 people across 1 different months, 2020 to 2022.

What it is

Part 10 of Corey Schafer's Django blog-app series, a 53-minute tutorial on Django's class-based views. He builds create, update and delete views for posts, using CreateView, UpdateView and DeleteView plus the login and user-test mixins.

What people said

Recommends Shiva Kharbanda · 2022-04 · Stack Overflow · on “how to populate user field with current user in django models via forms?”

ok so i found the answer. just had to change my view function a bit. if you want a detailed tutorial then please visit [this video] he explains in a much better way. class UserBuyPlan(LoginRequiredMixin, CreateView): model = Orders template_name = 'plans/plan.html' fields = ['pack'] def form_valid(self, form): form.instance.user = self.request.user return super().form_valid(form) and also had to add absolute url method to my orders model class Orders(models.Model): user = models.ForeignKey(CustomUser, on_delete = models.CASCADE) pack = models.ForeignKey(Plans, on_delete = models.CASCADE) start_date = models.DateField(auto_now_add=True) end_date = models.DateField(default=get_deadline()) is_active

Cites CutePoison · 2020-09 · Stack Overflow · on “Change the name of output of form-variables Django”

I'm following this Django guide [this video] for creating a "recipe" home-page, and I'm completly new to Django and html. I am using the CreateView class for creating a new class of the instance opskrift class opskrift(models.Model): title = models.CharField(max_length=100) algorithm = models.TextField() time_taken = models.CharField(max_length=10) prep_time = models.CharField(max_length=10) n_persons = models.CharField(max_length=5) def __str__(self): return self.title with the view class OpskriftCreateView(CreateView): model = opskrift fields = ["title","algorithm","time_taken","prep_time","n_persons"] The problem is, that it displays the variable names i.e n_persons , prep_time on the homepage

Cites Slash · 2021-03 · Stack Overflow · on “Basic Django POST not creating model with sqlite”

When I click the submit button, it redirects me to the create model (in this case create record) page, and does not actually create a new model, it doesn't appear in the main page which shows all models that were created. I tried following this tutorial: Link [this video] I feel like I did mostly the same things as him, and yet my form submission button does not create my post. The differences between our programs is simply the naming and the number of fields in my model. The user registration form works, but that is using a function based view, this is using a class based view (should still work as far as I know), and there are barely any differences between the model creation html and the user