How to insert session User id in database .?
I am trying to insert session login user id in database... here is my code view.py from django.shortcuts import render,redirect, Http404 from django.forms import ModelForm # Create your views here. from marketing.forms import EmailForm from marketing.models import MarketingMessage, Slider from .models import Product, ProductImage,Book,Category,Product from products.models import Product class DealsForm(ModelForm): class Meta: model = Product fields = ['title','description','category','price','sale_price','slug','active','update_defaults','user'] exclude = ('user',) def deals(request, template_name='products/deals.html'): form = DealsForm(request.POST or None) if form.is_valid(): form.save() return redirect('home') return render(request, template_name, {'form':form}) Model.py file from django.conf import settings from django.core.urlresolvers import reverse from django.db import models from django.db.models.signals import post_save from django.contrib.auth.models import User class Book(models.Model): name = models.CharField(max_length=200) pages = models.IntegerField() email = models.CharField(max_length=200) def __unicode__(self): return self.name class Category(models.Model): title = models.CharField(max_length=120) description = models.TextField(null=True, blank=True) slug = models.SlugField(unique=True) featured = models.BooleanField(default=None) timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) updated = models.DateTimeField(auto_now_add=False, auto_now=True) active = models.BooleanField(default=True) def __unicode__(self): return self.title class Product(models.Model): title = models.CharField(max_length=120) description = models.TextField(null=True, blank=True,max_length=200) category = models.ManyToManyField(Category, null=True, blank=True) price = models.DecimalField(decimal_places=2, max_digits=100, default=29.99) sale_price = models.DecimalField(decimal_places=2, max_digits=100,\ null=True, blank=True) slug = models.SlugField(unique=True) timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) updated = models.DateTimeField(auto_now_add=False, auto_now=True) active = models.BooleanField(default=True) update_defaults = models.BooleanField(default=False) user = models.ForeignKey(User) def __unicode__(self): return self.title class Meta: unique_together = ('title', 'slug') def get_price(self): return self.price def get_absolute_url(self): return reverse("single_product", kwargs={"slug": self.slug}) def my_view(request): product = DealsForm.save(commit=False) product.user = request.username product.save() class ProductImage(models.Model): product = models.ForeignKey(Product) image = models.ImageField(upload_to='products/images/') featured = models.BooleanField(default=False) thumbnail = models.BooleanField(default=False) active = models.BooleanField(default=True) updated = models.DateTimeField(auto_now_add=False, auto_now=True) def __unicode__(self): return self.product.title class VariationManager(models.Manager): def all(self): return super(VariationManager, self).filter(active=True) def sizes(self): return self.all().filter(category='size') def colors(self): return self.all().filter(category='color') VAR_CATEGORIES = ( ('size', 'size'), ('color', 'color'), ('package', 'package'), ) class Variation(models.Model): product = models.ForeignKey(Product) category = models.CharField(max_length=120, choices=VAR_CATEGORIES, default='size') title = models.CharField(max_length=120) image = models.ForeignKey(ProductImage, null=True, blank=True) price = models.DecimalField(max_digits=100, decimal_places=2, null=True, blank=True) updated = models.DateTimeField(auto_now_add=False, auto_now=True) active = models.BooleanField(default=True) objects = VariationManager() def __unicode__(self): return self.title def product_defaults(sender, instance, created, *args, **kwargs): if instance.update_defaults: categories = instance.category.all() print categories for cat in categories: print cat.id if cat.id == 1: #for t-shirts small_size = Variation.objects.get_or_create(product=instance, category='size', title='Small') medium_size = Variation.objects.get_or_create(product=instance, category='size', title='Medium') large_size = Variation.objects.get_or_create(product=instance, category='size', title='Large') instance.update_defaults = False instance.save() #print args, kwargs post_save.connect(product_defaults, sender=Product) can someone help me..? -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at
I have error like Type Error save() takes at least 2 arguments (1 given) in Django project.
view.py file class DealsForm(ModelForm): class Meta: model = Product fields = ['title','description','category','price','sale_price','slug','active','update_defaults','user'] exclude = ('user',) model.py file class Product(models.Model): title = models.CharField(max_length=120) description = models.TextField(null=True, blank=True,max_length=200) category = models.ManyToManyField(Category, null=True, blank=True) price = models.DecimalField(decimal_places=2, max_digits=100, default=29.99) sale_price = models.DecimalField(decimal_places=2, max_digits=100,\ null=True, blank=True) slug = models.SlugField(unique=True) timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) updated = models.DateTimeField(auto_now_add=False, auto_now=True) active = models.BooleanField(default=True) update_defaults = models.BooleanField(default=False) user = models.ForeignKey(User) def __unicode__(self): return self.title class Meta: unique_together = ('title', 'slug') def get_price(self): return self.price def get_absolute_url(self): return reverse("single_product", kwargs={"slug": self.slug}) def save(self, request, *args, **kwargs): obj = super(DealsForm, self).save(commit=False, *args, **kwargs) obj.user = request.user obj.save() Can you solve this problems ? -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c82101d3-992c-4aaa-b932-787cd417009f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Issue Django, in insert session login user data in database?
Actually I want to insert session login user data in database but I when I put this code I get all register user in Dropdown but I want to only current login user data not all and also I want to hide this field value.please help. model.py from django.conf import settingsfrom django.core.urlresolvers import reversefrom django.db import modelsfrom django.db.models.signals import post_savefrom django.contrib.auth.models import User class Product(models.Model): title = models.CharField(max_length=120) description = models.TextField(null=True, blank=True,max_length=200) category = models.ManyToManyField(Category, null=True, blank=True) price = models.DecimalField(decimal_places=2, max_digits=100, default=29.99) sale_price = models.DecimalField(decimal_places=2, max_digits=100,\ null=True, blank=True) slug = models.SlugField(unique=True) timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) updated = models.DateTimeField(auto_now_add=False, auto_now=True) active = models.BooleanField(default=True) update_defaults = models.BooleanField(default=False) user = models.ForeignKey(User) def __unicode__(self): return self.title class Meta: unique_together = ('title', 'slug') def get_price(self): return self.price def get_absolute_url(self): return reverse("single_product", kwargs={"slug": self.slug}) view.py class DealsForm(ModelForm):class Meta: model = Product fields = ['title','description','category','price','sale_price','slug','active','update_defaults','user'] last field user where I want to Insert current session login user data..how..? -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6119ac57-5a69-41ae-a7ae-a891d406766a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
'self' is not define
I am new in Django I am trying to insert session login username in database.but facing this error. my model.py file class Product(models.Model): title = models.CharField(max_length=120) description = models.TextField(null=True, blank=True) category = models.ManyToManyField(Category, null=True, blank=True) price = models.DecimalField(decimal_places=2, max_digits=100, default=29.99) sale_price = models.DecimalField(decimal_places=2, max_digits=100,\ null=True, blank=True) slug = models.SlugField(unique=True) timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) updated = models.DateTimeField(auto_now_add=False, auto_now=True) active = models.BooleanField(default=True) update_defaults = models.BooleanField(default=False) username=self.request.user.username view.py class DealsForm(ModelForm): class Meta: model = Product fields = ['title','description','category','price','sale_price','slug','active','update_defaults','Username'] pls 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2e411951-55f8-4434-a184-530d54e362bb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to insert recent session Username or UserId in database table in Django?
operationalError at/ no such column:products_product.User_id -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/715027d9-edf3-4d1c-8270-bc51e724f7f3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to insert recent session Username or UserId in database table in Django?
> > OperationalError at / >> >> no such column: products_product.User_id >> >> operationalError at/ no such column:products_product.User_id -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/040840b3-e8b2-4614-824c-d28e05f7b443%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to insert recent session Username or UserId in database table in Django?
thanks for your time, but I am facing error invalid syntax , on that line import django.contrib.auth.models import User my model.py from django.conf import settings from django.core.urlresolvers import reverse from django.db import models from django.db.models.signals import post_save import django.contrib.auth.models import User class Product(models.Model): title = models.CharField(max_length=120) description = models.TextField(null=True, blank=True) category = models.ManyToManyField(Category, null=True, blank=True) price = models.DecimalField(decimal_places=2, max_digits=100, default=29.99) sale_price = models.DecimalField(decimal_places=2, max_digits=100,\ null=True, blank=True) slug = models.SlugField(unique=True) timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) updated = models.DateTimeField(auto_now_add=False, auto_now=True) active = models.BooleanField(default=True) update_defaults = models.BooleanField(default=False) User = models.ForeignKey(User) def __unicode__(self): return self.title class Meta: unique_together = ('title', 'slug') def get_price(self): return self.price def get_absolute_url(self): return reverse("single_product", kwargs={"slug": self.slug}) my view.py class DealsForm(ModelForm): class Meta: model = Product fields = ['title','description','category','price','sale_price','slug','active','update_defaults','User'] pls 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a6da1496-ff2b-42ee-923e-8c3d3a34b017%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How to insert recent session Username or UserId in database table in Django?
I am new in Django, I am trying to make ecommerce project. I want to Insert recent login username or user Id in database by using formview code.so how to insert recent login username in database? Here is Model.py class Product(models.Model): title = models.CharField(max_length=120) description = models.TextField(null=True, blank=True) category = models.ManyToManyField(Category, null=True, blank=True) price = models.DecimalField(decimal_places=2, max_digits=100, default=29.99) sale_price = models.DecimalField(decimal_places=2, max_digits=100,\ null=True, blank=True) slug = models.SlugField(unique=True) timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) updated = models.DateTimeField(auto_now_add=False, auto_now=True) active = models.BooleanField(default=True) update_defaults = models.BooleanField(default=False) username = ? Here view.py class DealsForm(ModelForm): class Meta: model = Product fields = ['title','description','category','price','sale_price','slug','active','update_defaults','username'] I want to add Last field username insert in database but how ...? -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/76b28224-3259-460d-9e6f-8e830a5c03ad%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.