Hi @Андрей Сердюк,
Thank you for quick response.
Some clarifications please?
So you are saying that i need to create a new class for the category? the current code for one of my app where i am using category field is as below:
class Listing(models.Model):
user = models.ForeignKey(User, default=1, null=True, on_delete=models.SET_NULL)
title = models.CharField(max_length=120)
description = models.TextField()
phone_number = PhoneNumberField(blank=True, null=True)
fax_number = PhoneNumberField(blank=True, null=True)
null=True)
address1 = models.ForeignKey(Address, on_delete=models.CASCADE, related_name='addresses', blank=False, null=False)
address2 = AddressField(related_name='Address', on_delete=models.CASCADE, blank=False, null=False)
created_date = models.DateTimeField(auto_now=False, auto_now_add=True, null=False, blank=True)
updated = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(auto_now_add=True)
# category = models.ForeignKey(category, 'category.Category', help_text='Categorize this item.')
categories = models.ManyToManyField('category.Category', help_text='Categorize this item.')
tags = models.ManyToManyField('category.Tag', help_text='Tag this item.')
slug = AutoSlugField(populate_from='title', unique=True, null=False, blank=False)
I do not have a class for Category. I assumed that the django-category app would have it?
Also if i am to retrieve individual or multiple categories / tags related to the listing, how do i show the field in the form and also on the frontend?
Have currently tried to use "{{ Listing.Category.slug }}" / "{{ Listing.Category.title }}" these does not show up on the front end. It shows up blank. screen shot below.
Please advice.