Insert data into tables from form in Django

  Django

Email

step1: view.py 
     
def adminmainmenu(request):
if request.method =='POST':
form=Mainmenu_post(request.POST)
if form.is_valid():
new_item_text = request.POST['mainmenu_name'] Mainmenu.objects.create(mainmenu_name=new_item_text)
else:
new_item_text =''
return render(request, 'admin_super/home/mainmenu.html')
step2: models.py 

from django.db import models
 
class Mainmenu(models.Model):
mainmenu_name = models.CharField(max_length=300)
currentdate= models.DateField()
 
class Meta:
model=Mainmenu
fields=['title'] step3: form.py
from django import forms
from dqsadmin.models import Mainmenu
 
class Mainmenu_post(forms.Form):
mainmenu_name = forms.CharField(label='Create Main Menu', max_length=300)
 
Spread the Code

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of