Это модель Категорий
from django.db import models
class Answer_Category(models.Model):
title = models.CharField(max_length=200)
url = models.CharField(max_length=200,blank=True, null=True)
parent = models.ForeignKey('Answer_Category',blank=True, null=True)
description=models.CharField(max_length=200,blank=True, null=True)
path=models.CharField(max_length=200,blank=True, null=True)
metadesc=models.CharField(max_length=200,default='',blank=True, null=True)
published=models.BooleanField(default=True)
position=models.IntegerField(default=0)
def __str__(self):
return self.title
def save(self, *args, **kwargs):
url=slugify(self.title, 'ru')
self.url = url
super(Answer_Category, self).save(*args, **kwargs)
Это forms.py
from django import forms
from .models import Answer_Category
class AnswerForm(forms.Form):
title = forms.CharField(label='Название', max_length=100)
description = forms.CharField(label='Текст вопроса',widget=forms.Textarea)
email = forms.CharField(label='Email', max_length=100)
Как добавить список категорий из класса Answer_Category