Re: testing login problem
Hi, If you're using the SVN version you can try: >>> c = Client() >>> c.login(username='fred', password='secret') More info here: http://www.djangoproject.com/documentation/testing/ On Jul 1, 5:51 pm, laspal <[EMAIL PROTECTED]> wrote: > Hi, > > I am writing the test case but I am getting errors. > > Test case is as follows: > > import unittest > > from django.test.client import Client > from django.contrib.auth.models import User, Group > from ibm.crm.models import Industry > > class IndustryTest(unittest.TestCase): > > def setUp(self): > self.client = Client() > response =self.client.post('/ibm/login/', > {'username':'laspal', 'password':'abcd'}) > print response > > Getting error : > > > > Your username and password didn't match. > Please try again. > > for="id_username">Username : width="50%" class="loginbox"> class="vTextField required" name="username" size="15" value="laspal" > maxlength="30" /> > for="id_password">Password : width="50%" class="loginbox"> class="vPasswordField required" name="password" size="15" value="abcd" > maxlength="30" /> > class="button" type="submit" value="login" /> > > > > So my problem is its not getting login. > with same username and login I am able to login in the UI. > Does I have to include anything?? > > Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
a recent update broke form.save(commit=False) on FK fields
Hi, I updated Django to svn trunk v. 7811 from about a week old version. When saving a form (ModelForm instance) with a foreign key to another model, this used to work: photo = form.save(commit=False) photo.album = album photo.save() But now it raises a ValueError at the form.save(commit=False): ValueError: Cannot assign None: "Photo.album" does not allow null values. -- omat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: requiring fields in the admin page
By default all items are required. To make a field optional you have to use blank=True. Some interesting reading here: http://www.b-list.org/weblog/2006/jun/28/django-tips-difference-between-blank-and-null/ On Jul 1, 7:10 pm, keegan3d <[EMAIL PROTECTED]> wrote: > Hey guys, > > I am trying to make a couple of fields required in the admin page for > my app. I originally thought that core=True would do it but it makes > all the fields required, even ones that I did not specify core=True > for. After some further reading it seems like this is only used for > fields that are being edited in-line. > > Is there something I can set that will make the fields required before > the item will save? > > -Dave --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: a thread problem or my bad codes?
sorry for the bad indent of the "#models.py" part. I post it again, hope this time that part will be shown OK. #models.py class Apple_For_Sale(models.Model): price = models.PositiveSmallIntegerField() has_been_sold = models.BooleanField(default=False) class People(models.Model): money = models.PositiveSmallIntegerField() def buy_apple(self,apple): #apple should be an instance of Apple_For_Sale if self.money >= apple.price and not apple.has_been_sold: self.money -= apple.price self.save() apple.has_been_sold = True apple.save() Sale_Records.objects.create(apple=apple,people=self) class Sale_Records(models.Model): #create one record when one people buy apple = models.ForeignKey(Apple_For_Sale) people = models.ForeignKey(People) dealt_date = models.DateTimeField(auto_now_add=True) On Jul 1, 4:53 pm, pength <[EMAIL PROTECTED]> wrote: > I am using Django0.96/apache2/mod_python(running prefork MPM) / mysql, > for my Django project, a typical Django environment, I think. And > usually there're more than 10 apache2 processes running on my site, as > the online users is about 100+. > > I found a problem that sometimes if one user clicks a link several > times very fast (means several identical requests are sent to the > server), some error will happen. Although in my codes, I am tring to > prevent such thing. Let me make a simple example to illustrate my > problem. > > #models.py > class Apple_For_Sale(models.Model): > price = models.PositiveSmallIntegerField() > has_been_sold = models.BooleanField(default=False) > > class People(models.Model): > money = models.PositiveSmallIntegerField() > > def buy_apple(self,apple): #apple should be an instance of > Apple_For_Sale > if self.money >= apple.price and not apple.has_been_sold: > self.money -= apple.price > self.save() > apple.has_been_sold = True > apple.save() > > Sale_Records.objects.create(apple=apple,people=self) > > class Sale_Records(models.Model): #create one record when one people > buy > apple = models.ForeignKey(Apple_For_Sale) > people = models.ForeignKey(People) > dealt_date = models.DateTimeField(auto_now_add=True) > > #views.py > def people_buy_apple(request,aid): > "aid is the id of an apple_for_sale > a = get_object_or_404(Apple_For_Sale, pk=aid) > p = People.object.get(xxx) #get people...omitted here > p.buy_apple(a) > return > > The logic is simple. If the people has enough money and the apples > have not already been sold, then the "buy apple" will be successful. > > And in my site, I think 99% of such things happened correctly. But, > very rarely, when one user clicks a link of "buy apple" several times > fast, there'll be more than 1 records of Sale_Records created, for > same "apple" and "people", and the people's money was minused several > times for one identical apple. And if the network is laggy, it seems > the frequency of such error occurs becomes higher. > > For my understanding, when the several "identical requests" are sent > to my server, the requests are dispatched to different apache2 > processes, and nearly the same time, each process "think" the "buy > apple" can happen successfully. sothe error comes out. > > In my actual site, I have added some "unqiue = True" to avoid this > kind of error, in DB level. For example: > class Sale_Records(models.Model): > apple = models.ForeignKey(Apple_For_Sale, unique=True) > > But really I doubt this is the right way to solve my problem. > > Can anyone help? Can I avoid such error by using "mod_wsgi in daemon > mode with only 1 > thread " (ref. to > :http://groups.google.com/group/django-users/browse_thread/thread/5bd5...) > > Thanks a lot! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Sorting by a nullable ForeignKey
http://code.djangoproject.com/ticket/7582 On Tue, Jul 1, 2008 at 11:03 AM, Alex Rades <[EMAIL PROTECTED]> wrote: > Ok just tested and works. Lets open a ticket. > Thank you > > > On Tue, Jul 1, 2008 at 12:26 AM, Karen Tracey <[EMAIL PROTECTED]> wrote: > >> On Mon, Jun 30, 2008 at 5:51 PM, Alex Rades <[EMAIL PROTECTED]> wrote: >> >>> Hi Karen, >>> could you point me to the code in admin which is responsible for this >>> behaviour? I could produce a patch, do some testing and submit a ticket. >>> >> >> I've attached the patch from the changes I made while experimenting with >> this (sent direct since I don't know if the group supports posts with >> attachments). If you test it out and it works for you as well and nobody >> chimes in with a reason this is a bad idea, I'd say go ahead and open a >> ticket with the patch. >> >> Karen >> >> > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
requiring fields in the admin page
Hey guys, I am trying to make a couple of fields required in the admin page for my app. I originally thought that core=True would do it but it makes all the fields required, even ones that I did not specify core=True for. After some further reading it seems like this is only used for fields that are being edited in-line. Is there something I can set that will make the fields required before the item will save? -Dave --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: problem with models and foreign keys
On Tue, 2008-07-01 at 00:09 -0700, KevinTran wrote: > So that means that the tables are correct right? Yes, they're fine. It's just a subtle difference between what "manage.py sql ..." and "manage.py sqlall ..." prints out. When you run "manage.py syncdb", it will use the "sqlall" equivalent. > Is there a way to > control the order of the table creation? No. You don't need to. Django makes sure that the right "ALTER TABLE..." commands are run later to add cross-references that are needed. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
a thread problem or my bad codes?
I am using Django0.96/apache2/mod_python(running prefork MPM) / mysql, for my Django project, a typical Django environment, I think. And usually there're more than 10 apache2 processes running on my site, as the online users is about 100+. I found a problem that sometimes if one user clicks a link several times very fast (means several identical requests are sent to the server), some error will happen. Although in my codes, I am tring to prevent such thing. Let me make a simple example to illustrate my problem. #models.py class Apple_For_Sale(models.Model): price = models.PositiveSmallIntegerField() has_been_sold = models.BooleanField(default=False) class People(models.Model): money = models.PositiveSmallIntegerField() def buy_apple(self,apple): #apple should be an instance of Apple_For_Sale if self.money >= apple.price and not apple.has_been_sold: self.money -= apple.price self.save() apple.has_been_sold = True apple.save() Sale_Records.objects.create(apple=apple,people=self) class Sale_Records(models.Model): #create one record when one people buy apple = models.ForeignKey(Apple_For_Sale) people = models.ForeignKey(People) dealt_date = models.DateTimeField(auto_now_add=True) #views.py def people_buy_apple(request,aid): "aid is the id of an apple_for_sale a = get_object_or_404(Apple_For_Sale, pk=aid) p = People.object.get(xxx) #get people...omitted here p.buy_apple(a) return The logic is simple. If the people has enough money and the apples have not already been sold, then the "buy apple" will be successful. And in my site, I think 99% of such things happened correctly. But, very rarely, when one user clicks a link of "buy apple" several times fast, there'll be more than 1 records of Sale_Records created, for same "apple" and "people", and the people's money was minused several times for one identical apple. And if the network is laggy, it seems the frequency of such error occurs becomes higher. For my understanding, when the several "identical requests" are sent to my server, the requests are dispatched to different apache2 processes, and nearly the same time, each process "think" the "buy apple" can happen successfully. sothe error comes out. In my actual site, I have added some "unqiue = True" to avoid this kind of error, in DB level. For example: class Sale_Records(models.Model): apple = models.ForeignKey(Apple_For_Sale, unique=True) But really I doubt this is the right way to solve my problem. Can anyone help? Can I avoid such error by using "mod_wsgi in daemon mode with only 1 thread " (ref. to : http://groups.google.com/group/django-users/browse_thread/thread/5bd598dbdeebf326/8c9183f37a9ba0ef?lnk=gst&q=thread+safe+mpm#8c9183f37a9ba0ef) Thanks a lot! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
User Authentication - index/base
Hey, I've implemented a user login widget on my site. A simple 'Sign in' at top of every page that turns into 'Welcome John, View your profile' following successful user authentication. Works great - only issue I'm having is that on home page the text reverts to 'Sign In' even when user is logged in, only happens on this page. Not sure why this is occurring. Code below is sited in base.html. {% if user.is_authenticated %} Welcome, {{ user.username }}. Log Out | Your Profile | Blog | Promotions {% else %} Log in | Blog | Promotions {% endif %} Thanks in advance Allan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
testing login problem
Hi, I am writing the test case but I am getting errors. Test case is as follows: import unittest from django.test.client import Client from django.contrib.auth.models import User, Group from ibm.crm.models import Industry class IndustryTest(unittest.TestCase): def setUp(self): self.client = Client() response =self.client.post('/ibm/login/', {'username':'laspal', 'password':'abcd'}) print response Getting error : Your username and password didn't match. Please try again. Username : Password : So my problem is its not getting login. with same username and login I am able to login in the UI. Does I have to include anything?? Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: problem with models and foreign keys
So that means that the tables are correct right? Is there a way to control the order of the table creation? On Jul 1, 12:05 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Because the link table is created after the Bookmarks one that would > be a reference to a non-existant table, if you use the sqlall command > instead you will see that the tables are altered to add the > constraint. > > On Jul 1, 1:57 am, KevinTran <[EMAIL PROTECTED]> wrote: > > > Hi I'm currently reading Learning Website Development with Django and > > I'm having a problem with models. Here is my models.py: > > > from django.db import models > > from django.contrib.auth.models import User > > > class Link(models.Model): > > url = models.URLField(unique=True) > > > class Bookmark(models.Model): > > title = models.CharField(maxlength=200) > > link = models.ForeignKey(Link) > > user = models.ForeignKey(User) > > > The book says that if I run "python manage.py syncdb" and then "python > > manage.py sql bookmarks" then I should get the following: > > > BEGIN; > > CREATE TABLE "bookmarks_bookmark" ( > > "id" integer NOT NULL PRIMARY KEY, > > "title" varchar(200) NOT NULL, > > "user_id" integer NOT NULL REFERENCES > > "auth_user" ("id"), > > "link_id" integer NOT NULL REFERENCES > > "bookmarks_link" ("id"), > > ); > > CREATE TABLE "bookmarks_link" ( > > "id" integer NOT NULL PRIMARY KEY, > > "url" varchar(200) NOT NULL UNIQUE > > ); > > COMMIT; > > > What I actually get is: > > > BEGIN; > > CREATE TABLE "bookmarks_bookmark" ( > > "id" integer NOT NULL PRIMARY KEY, > > "title" varchar(200) NOT NULL, > > "link_id" integer NOT NULL, > > "user_id" integer NOT NULL REFERENCES "auth_user" ("id") > > ); > > CREATE TABLE "bookmarks_link" ( > > "id" integer NOT NULL PRIMARY KEY, > > "url" varchar(200) NOT NULL UNIQUE > > ); > > COMMIT; > > > Why does the link_id not get referenced as a foreign key the way the > > user_id does? I have a feeling that this is very simple, but I can't > > get my head around it. Thank you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: problem with models and foreign keys
Because the link table is created after the Bookmarks one that would be a reference to a non-existant table, if you use the sqlall command instead you will see that the tables are altered to add the constraint. On Jul 1, 1:57 am, KevinTran <[EMAIL PROTECTED]> wrote: > Hi I'm currently reading Learning Website Development with Django and > I'm having a problem with models. Here is my models.py: > > from django.db import models > from django.contrib.auth.models import User > > class Link(models.Model): > url = models.URLField(unique=True) > > class Bookmark(models.Model): > title = models.CharField(maxlength=200) > link = models.ForeignKey(Link) > user = models.ForeignKey(User) > > The book says that if I run "python manage.py syncdb" and then "python > manage.py sql bookmarks" then I should get the following: > > BEGIN; > CREATE TABLE "bookmarks_bookmark" ( > "id" integer NOT NULL PRIMARY KEY, > "title" varchar(200) NOT NULL, > "user_id" integer NOT NULL REFERENCES > "auth_user" ("id"), > "link_id" integer NOT NULL REFERENCES > "bookmarks_link" ("id"), > ); > CREATE TABLE "bookmarks_link" ( > "id" integer NOT NULL PRIMARY KEY, > "url" varchar(200) NOT NULL UNIQUE > ); > COMMIT; > > What I actually get is: > > BEGIN; > CREATE TABLE "bookmarks_bookmark" ( > "id" integer NOT NULL PRIMARY KEY, > "title" varchar(200) NOT NULL, > "link_id" integer NOT NULL, > "user_id" integer NOT NULL REFERENCES "auth_user" ("id") > ); > CREATE TABLE "bookmarks_link" ( > "id" integer NOT NULL PRIMARY KEY, > "url" varchar(200) NOT NULL UNIQUE > ); > COMMIT; > > Why does the link_id not get referenced as a foreign key the way the > user_id does? I have a feeling that this is very simple, but I can't > get my head around it. Thank you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
problem with models and foreign keys
Hi I'm currently reading Learning Website Development with Django and I'm having a problem with models. Here is my models.py: from django.db import models from django.contrib.auth.models import User class Link(models.Model): url = models.URLField(unique=True) class Bookmark(models.Model): title = models.CharField(maxlength=200) link = models.ForeignKey(Link) user = models.ForeignKey(User) The book says that if I run "python manage.py syncdb" and then "python manage.py sql bookmarks" then I should get the following: BEGIN; CREATE TABLE "bookmarks_bookmark" ( "id" integer NOT NULL PRIMARY KEY, "title" varchar(200) NOT NULL, "user_id" integer NOT NULL REFERENCES "auth_user" ("id"), "link_id" integer NOT NULL REFERENCES "bookmarks_link" ("id"), ); CREATE TABLE "bookmarks_link" ( "id" integer NOT NULL PRIMARY KEY, "url" varchar(200) NOT NULL UNIQUE ); COMMIT; What I actually get is: BEGIN; CREATE TABLE "bookmarks_bookmark" ( "id" integer NOT NULL PRIMARY KEY, "title" varchar(200) NOT NULL, "link_id" integer NOT NULL, "user_id" integer NOT NULL REFERENCES "auth_user" ("id") ); CREATE TABLE "bookmarks_link" ( "id" integer NOT NULL PRIMARY KEY, "url" varchar(200) NOT NULL UNIQUE ); COMMIT; Why does the link_id not get referenced as a foreign key the way the user_id does? I have a feeling that this is very simple, but I can't get my head around it. Thank you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---