I
I
IvanOne2014-12-22 12:39:33
Django
IvanOne, 2014-12-22 12:39:33

What is the best way to create a form in Django?

there is this model:

class Category(models.Model):

    name = models.CharField(u"Название категории", max_length=100)

    def __unicode__(self):
        return self.name



class Chat(models.Model):
    category = models.ForeignKey(Category, name="category", verbose_name=u"Категория")
    user = models.ForeignKey(User, name="user", verbose_name=u"Пользователь")
    date = models.DateTimeField(u"Дата создания", auto_now_add=True)
    objects = TicketManager()


class ChatMessages(models.Model):
    ticket = models.ForeignKey(Chat, related_name="messages")
    text = models.TextField(u"Сообщение")
    user = models.ForeignKey(User)

I need to create a form to create a chat and a message, I wrote a form model but I don’t know how to add a field there to create a ChatMessages object
here is the form code:
class ChatForm(forms.ModelForm):
class Meta:
model = Chat
fields = ['category']
tell me how do or point to the place in the documentation, maybe I missed something

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question