Hello!
well in the form is there anything that will be saved in a database?
if so you can start by looking at models.py in your application.
if not you can jump directly to forms.py.
an example of a model and form:
*** in models.py
from django.db import models
class Company(models.Model):
"""This is your database model with the fields you want to store and fetch!
"""
name = models.CharField(max_length=60)
telephone = models.CharField(max_length=15, null=True, blank=True)
info = models.TextField(blank=True, null=True)
is_awesome = models.BooleanField(default=False)
*** in forms.py
from django import forms
from .models import Company
class CompanyForm(forms.ModelForm):
class Meta:
model = Company
fields = '__all__'
widgets = {
'is_awesome': forms.HiddenInput(),
}
then when you have a form and model you can use the generic views like this:
*** in views.py
from django.urls import reverse_lazy
from django.views.generic import CreateView
from django.contrib.messages.views import SuccessMessageMixin
from .models import Company
from .forms import CompanyForm
class Add_Company(SuccessMessageMixin, CreateView):
template_name = 'company/add_a_new.html'
success_message = 'a new company was added!'
success_url = reverse_lazy('home')
form_class = CompanyForm
thats it!
Den tis 9 apr. 2019 kl 00:20 skrev Bassem Boulfarkat <bassem.boulfarkat@gmail.com>:
--I am working on creating a website based on the django framework with python. The aim is to have a simple HTML form that will build around where the user fills in the form and when it is done can submit it. When submitted, he will have a json file downloaded.
After looking around, I found that serializer would be the best way but I am still really confused. Would appreciate any kind of help.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3bd76a23-e5d8-4597-8fc1-3e9f2fc7cb90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPLZMbNnCxVTa%2BXkpGHYSrwYjYPMyvfhtrsTMpkY0E_dxvT16A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment