hi, how can I insert logged in username insert into a table column named is " createdby" at the time of the insert brand name .
Please help me .. Thanks in advance. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1fab48fe-4c62-4b4a-8572-c6b9c9b7f540%40googlegroups.com.Title: {% block title %}Brand{% endblock %}
Store Name
Lorem ipsum dolor sit ame.
{% csrf_token %}
Brand Entry
{{ form.brand_name }}
from django.shortcuts import render,redirect from stock.forms import BrandForm from stock.models import Brand # Create your views here. def BrandInsert(request): if request.method == "POST": createdBy = request.POST.get('username') form = BrandForm(request.POST) if form.is_valid(): try: form.save() print(user) return redirect('/BrandShow') except : pass else: form = BrandForm() return render (request,"brand_insert.html",{'form': form}) def BrandShow(request): sbrand = Brand.objects.all() return render (request,"brandlist.html",{'sbrand':sbrand}) def BrandEdit(request,id): ebrand = Brand.objects.get(id=id) print(ebrand) return render (request,"brand_edit.html",{'ebrand':ebrand}) def BrandUpdate(request,id): ubrand = Brand.objects.get(id=id) form = BrandForm(request.POST, instance= ubrand) if form.is_valid(): form.save() return redirect('/BrandShow') return render (request,"brand_edit.html",{'ubrand':ubrand}) def BrandDelete(request,id): dbrand = Brand.objects.get(id=id) dbrand.delete() return redirect('/BrandShow')
from django.db import models # Create your models here. class Brand(models.Model): createdBy = models.CharField(max_length=20,blank=False) brand_name = models.CharField(max_length=50,unique=True) flag =models.BooleanField() #createdon = models.DateField(auto_now_add=True) #updatedon = models.DateField(auto_now=True,) class meta: db_table = 'brand' class Category(models.Model): brand = models.CharField(max_length=50,) category_name = models.CharField(max_length=50,unique=True) flag =models.BooleanField() class meta: db_table = 'category' class Subcategory(models.Model): category = models.CharField(max_length=50,) subcategory_name = models.CharField(max_length=50,unique=True) flag =models.BooleanField() class meta: db_table = 'subcategory' class Unit(models.Model): #brand_id = models.IntegerField() unit_name = models.CharField(max_length=50) flag =models.BooleanField() class meta: db_table = 'unit'
from django import forms from stock.models import Brand,Category,Subcategory,Unit class BrandForm(forms.ModelForm): class Meta: model = Brand fields = "__all__" class CategoryForm(forms.ModelForm): class Meta: model = Category fields = "__all__" class SubCatForm(forms.ModelForm): class Meta: model = Subcategory fields = "__all__" class UnitForm(forms.ModelForm): class Meta: model = Unit fields = "__all__"