Add Blog Categories - Django Blog #12

preview_player
Показать описание
In this video we'll start to add categories to our blog with Django.

So you've got a blog, but you want to be able to designate a 'category' for each blog post. We'll start out by adding a category field to our Post database model. Then we'll create a whole new model named Category.

This new model will allow us to add, edit, or remove Categories from the blog itself in the future (as opposed to just hard coding in the categories on the backend).

Рекомендации по теме
Комментарии
Автор

▶️ Watch Entire Django Blog Playlist ✅ Subscribe To My YouTube Channel:
▶️ See More At: ✅ Join My Facebook Group:

Codemycom
Автор

Also, if you want to fix 'Categorys', add this meta class in your model:

class Meta:
verbose_name_plural = "Categories"

smishra
Автор

the best method you can create:
category= models.ForeignKey(Caterory, max_length=60, on_delete=models.CASCADE, related_name= 'catego')

ibrahimhennihaouas
Автор

Excellent channel, I've been learning quite a bit from you on Django. You've got yourself another subscriber.

EzekielCarvalho
Автор

I think you are the only one that gives attention to the default property. Other vids over Youtube do not mention that. A lot of students delete db.sqlite3 and migrations (not the __init__) and then do a migration of all Data Base. Of course, with this, you do not have errors when migrating the database. But, for me, it´s so much better to understand the default property and do not lose data on the future... Great Material.

andrenevares
Автор

Sir, your videos are a great great help to someone like me who struggles with django

akshitkushwaha
Автор

Am no longer rushing, am staying this helps to master the content.

unchart_d
Автор

A great tutorial about Python Django! Thanks a lot! Best regards from Austria (Vienna)! - Your tutorial about Python's Tkinter will be my next stop!

romanbuchta
Автор

Like the Bob Ross of Django. Great stuff

JHHandwerk
Автор

i am suprized the you are covering every aspect of a website. Now I know why there are so many videos in the playlist

Morimove
Автор

Hi, Jhon, Thanks for this Django Series.

As a feedback I think that it's better to create a Foreign key in Post.category field instead of the query you did.😄

danieldiaz
Автор

great tutorial.
any ideas how to skip restarting the server?
I've noticed that the category appears after some time even without restrating the server, but are there any ways to make it instant, just like adding posts?

justasnom
Автор

i hope we can see more projects in the near future .ps : love your vids. keep up the good work and your chanel will grow evantually .

universitystudio
Автор

Wouldn't it be easeir to make category a foreign key with "on_delete=SET_DEFAULT" set to something like "misc" so the post wouldn't be deleted if you deleted certain category and you wouldn't have to do a query on forms.py?

sayori
Автор

Great tutorial! Here are my 2 cents to make the `choices` code a bit more pythonic-

choices = Category.objects.all().values_list('name', 'name')
choice_list = [choice for choice in choices]

smishra
Автор

I from Ukraine and my english so bad, but you so good in explanation and it`s great, thank you so much

СвятославЛитвин-лй
Автор

Your videos and explanations are just amazinggg!!

muzy_mess
Автор

Love the video, had a few suggestions for videos (don't feel pressure), comments, like button, slugs (choose the url), and author pages!

andrewwebberley
Автор

If you are wondering how to add the category option to the edit form:

Open up your forms.py. Under Meta>fields, include "category'

Then under widgets, include the following code where you want your categories to show up:
'category': forms.Select (choices= choice_list, attrs= {'class': 'form-control'}),

Save and then refresh your work.

som
Автор

should i use like this ?
categories = models.ManyToManyField('category.Category', help_text='Categorize this item.')

TungNguyen-fmbt