Re: Keys composed of multiple fields
I see. Thank you. Alex Koshelev wrote: > Django doesn't suppurt multi-field PKs. Try to search this group for more > diussion. > > On Mon, Feb 16, 2009 at 12:43 PM, jfmxl wrote: > > > > > Hi again, > > > > How do I handle multifield keys? > > > > I have multifield primary keys which are in turn used as foreign keys > > in other tables. > > > > My database backend is MySQL if that makes a difference. > > > > > --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Keys composed of multiple fields
Hi again, How do I handle multifield keys? I have multifield primary keys which are in turn used as foreign keys in other tables. My database backend is MySQL if that makes a difference. --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: InnoDB tables for MySQL
On Feb 16, 2:24 pm, Alex Gaynor wrote: > On Mon, Feb 16, 2009 at 1:37 AM, jfmxl wrote: > > > Hi, > > > I read through the tutorials and thank you very much! They are well > > designed and very helpful. > > > I noticed that the models' database definitions created using MySQL > > always create MyISAM tables, but to use functional constraints on > > foreign keys one must use InnoDB tables in MySQL. > > > Is there someway to change the table type created from MyISAM to > > MyInnoDB with MySQL? > > By adding: > > DATABASE_OPTIONS = { > "init_command": "SET storage_engine=INNODB", > > } > > you can get innodb tables by default. > > Alex Thanks very much! Now for primary keys using multiple fields... but I'll open another thread. > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
InnoDB tables for MySQL
Hi, I read through the tutorials and thank you very much! They are well designed and very helpful. I noticed that the models' database definitions created using MySQL always create MyISAM tables, but to use functional constraints on foreign keys one must use InnoDB tables in MySQL. Is there someway to change the table type created from MyISAM to MyInnoDB with MySQL? --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Troubles with unicode in django-trunk
On Feb 9, 8:22 pm, Karen Tracey wrote: > On Mon, Feb 9, 2009 at 8:07 AM, jfmxl wrote: > > > # Create your models here. > > > class Poll(models.Model): > > question = models.CharField(max_length=200) > > pub_date = models.DateTimeField('date published') > > > class Choice(models.Model): > > poll = models.ForeignKey(Poll) > > choice = models.CharField(max_length=200) > > votes = models.IntegerField() > > > class Poll(models.Model): > > # ... > > def __unicode__(self): > > return self.question > > > class Choice(models.Model): > > # ... > > def __unicode__(self): > > return self.choice > > > class Poll(models.Model): > > # ... > > def was_published_today(self): > > return self.pub_date.date() == datetime.date.today() > > You're only supposed to have one class Poll(...), class Choice(...), etc. > line. When you add a method like __unicode__ or was_published_today, simply > append it (properly indented) to the existing class Poll(...) you already > have. Do not add another class Poll(...) line. Well... thank you very much Karen! > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Troubles with unicode in django-trunk
On Feb 9, 7:05 pm, Russell Keith-Magee wrote: > On Mon, Feb 9, 2009 at 8:43 PM, jfmxl wrote: > > > On Feb 9, 5:21 pm, Russell Keith-Magee wrote: > >> On Mon, Feb 9, 2009 at 6:58 PM, jfmxl wrote: > > Sorry, I am new to python and I guess you hadn't bothered to read the > > elementary tutorial that I was following. I should have been more > > specific: > > Specifics always help. And FYI: I have read the tutorial. I'm one of > the core developers of Django, so I'm well aware of what the tutorial > says. I'm sorry. I didn't mean to accuse you of negligence at all! I just meant that as an experienced python programmer you might have had a different entry point to django than I did. I was unaware that you are of the core. My apologies in any case. > > So it was in response to that advice that I "saw he installation docs > > for more information" and didn't find the relief spoken of and so > > wrote here. > > > Thanks for your help, but I still am having a problem. > > Without seeing your code, its almost impossible to determine the cause > of your problem. My initial guess would be that one of three things > has happened: > > 1) You haven't actually saved the models.py file where you have > defined the __unicode__() methods. An obvious error, but a > surprisingly common one. Yes. Just the sort of mistake I'm prone to make too. But not this time. > 2) You haven't restarted your python shell - you've just continued > working with an old shell. You need to start a new Python shell > session to force the models.py file to be reloaded. I actually thought of that one myself after the first or second run. > 3) You've misspelled __unicode__ in your models.py file. Most likely > culprit here - using single underscores rather than double underscores > in the method name. The method needs to be called _ _ unicode _ _ > (self). If you have used a different name, you won't see an error > (since the alternate name will be a valid Python method name) but it > won't generate the output you expect. I've double-checked and that's not the case. I had cut and pasted the code in question. > If you post your example code as it currently stands, we may be able > to provide more assistance. I'm sorry it's so lengthy: j...@ws0:~/src/python/django/mysite$ django-admin.py --version 1.1 pre-alpha SVN-9820 j...@ws0:~/src/python/django/mysite$ cat polls/models.py from django.db import models import datetime # ... # Create your models here. class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() class Poll(models.Model): # ... def __unicode__(self): return self.question class Choice(models.Model): # ... def __unicode__(self): return self.choice class Poll(models.Model): # ... def was_published_today(self): return self.pub_date.date() == datetime.date.today() j...@ws0:~/src/python/django/mysite$ ./manage.py shell Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) Type "copyright", "credits" or "license" for more information. IPython 0.8.4 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: from mysite.polls.models import Poll, Choice In [2]: Poll.objects.all() Out[2]: [] In [3]: Poll.objects.filter(id=1) Out[3]: [] In [4]: Poll.objects.filter(question__startswith='What') Out[4]: [] In [5]: Poll.objects.get(pub_date__year=2009) Out[5]: In [6]: Poll.objects.get(id=2) --- DoesNotExist Traceback (most recent call last) /home/jfl/src/python/django/mysite/ in () /usr/lib/python2.5/site-packages/django/db/models/manager.py in get (self, *args, **kwargs) 91 92 def get(self, *args, **kwargs): ---> 93 return self.get_query_set().get(*args, **kwargs) 94 95 def get_or_create(self, **kwargs): /usr/lib/python2.5/site-packages/django/db/models/query.py in get (self, *args, **kwargs) 340 if not num: 341 raise self.model.DoesNotExist("%s matching query does not exist." --> 342 % self.model._meta.object_name) 343 raise self.model.MultipleObjectsReturned("get() returned more than one %s -- it returned %s! Lookup parameter
Re: Troubles with unicode in django-trunk
On Feb 9, 5:21 pm, Russell Keith-Magee wrote: > On Mon, Feb 9, 2009 at 6:58 PM, jfmxl wrote: > > > Hello, > > > I downloaded the 1.0.2 version of django to my ubuntu 8.10 box and > > began the tutorial. I got as far as adding the unicode print > > definitions for poll and choice, and then saw no difference between > > afterward : > > > In [2]: Poll.objects.all() > > Out[2]: [] > > > is still what I saw. > > What were you expecting to see? This output indicates that you are > using the default __unicode__ method for the Poll object, which won't > be printing any detail of the object itself - just the fact that it is > a Poll object. Sorry, I am new to python and I guess you hadn't bothered to read the elementary tutorial that I was following. I should have been more specific: http://docs.djangoproject.com/en/dev/intro/tutorial01/?from=olddocs about 7/8s' of the way down the page : Wait a minute. is, utterly, an unhelpful representation of this object. Let's fix that by editing the polls model (in the polls/models.py file) and adding a __unicode__() method to both Poll and Choice: class Poll(models.Model): # ... def __unicode__(self): return self.question class Choice(models.Model): # ... def __unicode__(self): return self.choice If __unicode__() doesn't seem to work If you add the __unicode__() method to your models and don't see any change in how they're represented, you're most likely using an old version of Django. (This version of the tutorial is written for the latest development version of Django.) If you're using a Subversion checkout of Django's development version (see the installation docs for more information), you shouldn't have any problems. If you want to stick with an older version of Django, you'll want to switch to the Django 0.96 tutorial, because this tutorial covers several features that only exist in the Django development version. It's important to add __unicode__() methods to your models, not only for your own sanity when dealing with the interactive prompt, but also because objects' representations are used throughout Django's automatically-generated admin. So it was in response to that advice that I "saw he installation docs for more information" and didn't find the relief spoken of and so wrote here. Thanks for your help, but I still am having a problem. > > If you retrieve an individual object from the list that has been > returned, you will be able to interrogate the individual fields of > that object, and you should find that they hold unicode data. > > Alternatively, you can provide a definition for the __unicode__() > method for the Poll class, and it will print whatever you desire (for > example the poll title, not just "Poll object") > > > Can you imagine what they problem might be? > > No problem here - just a misunderstanding of usage. I'm guessing > you're new to Python - by way of guidance, this isn't a > Django-specific feature. It's a part of the way the Python shell tells > you what objects you are working with. You may find it illuminating to > dig into the Python documentation around the __unicode__, __str__ and > __repr__ methods. > > Yours, > Russ Magee %-) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Troubles with unicode in django-trunk
Hello, I downloaded the 1.0.2 version of django to my ubuntu 8.10 box and began the tutorial. I got as far as adding the unicode print definitions for poll and choice, and then saw no difference between afterward : In [2]: Poll.objects.all() Out[2]: [] is still what I saw. So I scrubbed the 1.0.2 and got the svn version, but there is still no difference. I removed and relinked the /usr/lib/python2.5/site-packages/django directory and /usr/lib/django-admin.py file as recommended. I really need unicode to work. Can you imagine what they problem might be? --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---