Answer the question
In order to leave comments, you need to log in
In Django in forms.py in html to display list of categories from model?
This is the category model
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)
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 the question
In order to leave comments, you need to log in
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)
category = forms.ModelChoiceField(queryset=Answer_Category.objects.all(), empty_label="Выберите значение")
email = forms.CharField(label='Email', max_length=100)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question