Friday, August 21, 2015

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 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 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+unsubscribe@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.

No comments:

Post a Comment