Re: Is there a workaround for MySQLdb's failure to handle unicode?
The problem is worse than I initially thought. Not only are unicode characters are unsupported during deserialization from a fixture, they are not supported at all. If I try to manually enter unicode characters through the Django database admin UI, I get the same error message. So currently my site does not support unicode. On Sep 30, 11:44 am, "W.P. McNeill" <bill...@gmail.com> wrote: > Some of the fields in my application's database contain unicode > strings. I serialized this database into a fixture. When I try to > load that fixture into a machine running MySQL I get an warning from > MySQLdb/cursors.py about an "Incorrect string value" and my database > is left incomplete. The same thing happens if I serialize to .xml > or .json > > Googling around it looks like there are issues with configuring > MySQLdb to properly handle unicode, but I couldn't find a clear > workaround. Does anyone know how I can import a database from a table > containing unicode? > > Thanks. > > Here is the full error: > > $ python2.6 manage.py syncdb > /opt/python-2.6/lib/python2.6/site-packages/MySQL_python-1.2.2-py2.6- > linux-x86_64.egg/MySQLdb/__init__.py:34: DeprecationWarning: the sets > module is deprecated > Installing json fixture 'initial_data' from '/projects/lingshare/web- > interface/lingshare/../lingshare/phonemechart/fixtures'. > Problem installing fixture '/projects/lingshare/web-interface/ > lingshare/../lingshare/phonemechart/fixtures/initial_data.json': > Traceback (most recent call last): > File "/opt/python-2.6/lib/python2.6/site-packages/django/core/ > management/commands/loaddata.py", line 153, in handle > obj.save() > File "/opt/python-2.6/lib/python2.6/site-packages/django/core/ > serializers/base.py", line 163, in save > models.Model.save_base(self.object, raw=True) > File "/opt/python-2.6/lib/python2.6/site-packages/django/db/models/ > base.py", line 474, in save_base > rows = manager.filter(pk=pk_val)._update(values) > File "/opt/python-2.6/lib/python2.6/site-packages/django/db/models/ > query.py", line 444, in _update > return query.execute_sql(None) > File "/opt/python-2.6/lib/python2.6/site-packages/django/db/models/ > sql/subqueries.py", line 120, in execute_sql > cursor = super(UpdateQuery, self).execute_sql(result_type) > File "/opt/python-2.6/lib/python2.6/site-packages/django/db/models/ > sql/query.py", line 2369, in execute_sql > cursor.execute(sql, params) > File "/opt/python-2.6/lib/python2.6/site-packages/django/db/backends/ > util.py", line 19, in execute > return self.cursor.execute(sql, params) > File "/opt/python-2.6/lib/python2.6/site-packages/django/db/backends/ > mysql/base.py", line 84, in execute > return self.cursor.execute(query, args) > File "build/bdist.linux-x86_64/egg/MySQLdb/cursors.py", line 168, in > execute > if not self._defer_warnings: self._warning_check() > File "build/bdist.linux-x86_64/egg/MySQLdb/cursors.py", line 82, in > _warning_check > warn(w[-1], self.Warning, 3) > Warning: Incorrect string value: '\xC9\x92' for column 'ipa' at row 1 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Is there a workaround for MySQLdb's failure to handle unicode?
Some of the fields in my application's database contain unicode strings. I serialized this database into a fixture. When I try to load that fixture into a machine running MySQL I get an warning from MySQLdb/cursors.py about an "Incorrect string value" and my database is left incomplete. The same thing happens if I serialize to .xml or .json Googling around it looks like there are issues with configuring MySQLdb to properly handle unicode, but I couldn't find a clear workaround. Does anyone know how I can import a database from a table containing unicode? Thanks. Here is the full error: $ python2.6 manage.py syncdb /opt/python-2.6/lib/python2.6/site-packages/MySQL_python-1.2.2-py2.6- linux-x86_64.egg/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated Installing json fixture 'initial_data' from '/projects/lingshare/web- interface/lingshare/../lingshare/phonemechart/fixtures'. Problem installing fixture '/projects/lingshare/web-interface/ lingshare/../lingshare/phonemechart/fixtures/initial_data.json': Traceback (most recent call last): File "/opt/python-2.6/lib/python2.6/site-packages/django/core/ management/commands/loaddata.py", line 153, in handle obj.save() File "/opt/python-2.6/lib/python2.6/site-packages/django/core/ serializers/base.py", line 163, in save models.Model.save_base(self.object, raw=True) File "/opt/python-2.6/lib/python2.6/site-packages/django/db/models/ base.py", line 474, in save_base rows = manager.filter(pk=pk_val)._update(values) File "/opt/python-2.6/lib/python2.6/site-packages/django/db/models/ query.py", line 444, in _update return query.execute_sql(None) File "/opt/python-2.6/lib/python2.6/site-packages/django/db/models/ sql/subqueries.py", line 120, in execute_sql cursor = super(UpdateQuery, self).execute_sql(result_type) File "/opt/python-2.6/lib/python2.6/site-packages/django/db/models/ sql/query.py", line 2369, in execute_sql cursor.execute(sql, params) File "/opt/python-2.6/lib/python2.6/site-packages/django/db/backends/ util.py", line 19, in execute return self.cursor.execute(sql, params) File "/opt/python-2.6/lib/python2.6/site-packages/django/db/backends/ mysql/base.py", line 84, in execute return self.cursor.execute(query, args) File "build/bdist.linux-x86_64/egg/MySQLdb/cursors.py", line 168, in execute if not self._defer_warnings: self._warning_check() File "build/bdist.linux-x86_64/egg/MySQLdb/cursors.py", line 82, in _warning_check warn(w[-1], self.Warning, 3) Warning: Incorrect string value: '\xC9\x92' for column 'ipa' at row 1 --~--~-~--~~~---~--~~ 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: Incorrect Python path in Apache FCGI deployment
I figured out the first problem listed above. It wasn't related to file permissions, but I want to document it here since if I hit it someone else is likely to hit it too. The problem was because I was writing application import statements incorrectly. For example, I was saying: from phonemechart.views import * This worked on my development machine but failed in deployment. If I change this to: from lingshare.phonemechart.views import * everything works. Lesson learned: write import statements in application files relative to the entire site instead of relative to the application. I'm still confused about why it worked on my development machine because the relative sys.paths don't appear to be set any differently there. I also tried uncommenting the os.chdir("/somepath/web- interface/lingshare") line in my .fcgi file, but this did not fix the problem. Thanks for your suggestion about permissions. I probably have some of those problems in here too. :-) On Sep 30, 10:00 am, Karen Tracey <kmtra...@gmail.com> wrote: > On Wed, Sep 30, 2009 at 12:47 PM, W.P. McNeill <bill...@gmail.com> wrote: > > > Because this appears to be a problem with load paths, I inserted code > > at the top of phonemechart/urls.py just above the import statements to > > write out the system path. > > > import sys > > > f = open('/tmp/pypath', 'w') > > f.write("Path is: %s" % sys.path) > > f.close > > > from django.conf.urls.defaults import * > > ... > > > The file in /tmp/mypath shows that "/somepath/web-interface/lingshare" > > is on the head of the sys.path as it should be. > > > I'm completely blocked. Can someone give me an idea of where to start > > debugging next? > > If you are sure the paths are set correctly, then the next thing to check is > permissions. Does the web server process have the right permissions to > access the files? > > 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: Incorrect Python path in Apache FCGI deployment
Because this appears to be a problem with load paths, I inserted code at the top of phonemechart/urls.py just above the import statements to write out the system path. import sys f = open('/tmp/pypath', 'w') f.write("Path is: %s" % sys.path) f.close from django.conf.urls.defaults import * ... The file in /tmp/mypath shows that "/somepath/web-interface/lingshare" is on the head of the sys.path as it should be. I'm completely blocked. Can someone give me an idea of where to start debugging next? On Sep 28, 12:36 pm, "W.P. McNeill" <bill...@gmail.com> wrote: > I have written a set of Django apps that works on my development > machine but fails when I deploy it to Apache. The issue appears to be > with the Python path that the Apache process is using, but none of the > things I have tried have worked. I'm looking for suggestions as to > what I am doing wrong. > > I have a Django project called lingshare. There are two applications > in this project: phonemechart and search. I am hosting this project > on a shared hosting provider with Apache and follwing the instructions > here:http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#runnin > The directory layout on my Apache machine looks like this: > > /somepath/web-interface > lingshare.fcgi > /somepath/web-interface/templates > /somepath/web-interface/lingshare > __init__.py, manage.py, settings.py, urls.py > phonemechart > search > > The phonemechart and search directories contain my Django > applications. They contain __init__.py, admin.py, models.py, etc. > files. > > When I try to access my phonemechart application (http://myserver/ > somewebpath/lingshare/phonemechart) I get a generic "Unhandled > Exception" page. When I look in the Apache log I see that the problem > is that the models file for this application is not being loaded. > > ... > self._urlconf_module = import_module(self.urlconf_name) > File "/opt/python-2.6/lib/python2.6/site-packages/django/utils/ > importlib.py", line 35, in import_module > __import__(name) > File "/projects/lingshare/web-interface/lingshare/phonemechart/ > urls.py", line 3, in > from phonemechart.models import * > ImportError: No module named phonemechart.models > > The phonemechart directory contains a models.py file. The same code > works fine when I run it locally on my development machine. > > My lingshare.fcgi file looks like this: > > #!/opt/python-2.6/bin/python2.6 > import sys, os > > # Add a custom python path. > sys.path.insert(0, "/somepath/web-interface/lingshare") > > # Set the DJANGO_SETTINGS_MODULE environment variable. > os.environ['DJANGO_SETTINGS_MODULE'] = "lingshare.settings" > > # Set the egg cache to somewhere the web server can write to > os.environ['PYTHON_EGG_CACHE'] = '/tmp' > > from django.core.servers.fastcgi import runfastcgi > runfastcgi(method="threaded", daemonize="false") > > I have also tried the following Python path line: > > sys.path.insert(0, "/somepath/web-interface") > > I get the same error. > > The search application works. I think this is because it is a toy app > that does not try to call "import search.models". > > Questions: > 1. What should my sys.path.insert line look like? > 2. Are there other configuration details I'm overlooking? > > This is Django version 1.1. > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Incorrect Python path in Apache FCGI deployment
I have written a set of Django apps that works on my development machine but fails when I deploy it to Apache. The issue appears to be with the Python path that the Apache process is using, but none of the things I have tried have worked. I'm looking for suggestions as to what I am doing wrong. I have a Django project called lingshare. There are two applications in this project: phonemechart and search. I am hosting this project on a shared hosting provider with Apache and follwing the instructions here: http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache. The directory layout on my Apache machine looks like this: /somepath/web-interface lingshare.fcgi /somepath/web-interface/templates /somepath/web-interface/lingshare __init__.py, manage.py, settings.py, urls.py phonemechart search The phonemechart and search directories contain my Django applications. They contain __init__.py, admin.py, models.py, etc. files. When I try to access my phonemechart application (http://myserver/ somewebpath/lingshare/phonemechart) I get a generic "Unhandled Exception" page. When I look in the Apache log I see that the problem is that the models file for this application is not being loaded. ... self._urlconf_module = import_module(self.urlconf_name) File "/opt/python-2.6/lib/python2.6/site-packages/django/utils/ importlib.py", line 35, in import_module __import__(name) File "/projects/lingshare/web-interface/lingshare/phonemechart/ urls.py", line 3, in from phonemechart.models import * ImportError: No module named phonemechart.models The phonemechart directory contains a models.py file. The same code works fine when I run it locally on my development machine. My lingshare.fcgi file looks like this: #!/opt/python-2.6/bin/python2.6 import sys, os # Add a custom python path. sys.path.insert(0, "/somepath/web-interface/lingshare") # Set the DJANGO_SETTINGS_MODULE environment variable. os.environ['DJANGO_SETTINGS_MODULE'] = "lingshare.settings" # Set the egg cache to somewhere the web server can write to os.environ['PYTHON_EGG_CACHE'] = '/tmp' from django.core.servers.fastcgi import runfastcgi runfastcgi(method="threaded", daemonize="false") I have also tried the following Python path line: sys.path.insert(0, "/somepath/web-interface") I get the same error. The search application works. I think this is because it is a toy app that does not try to call "import search.models". Questions: 1. What should my sys.path.insert line look like? 2. Are there other configuration details I'm overlooking? This is Django version 1.1. 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: When did Paul join the Beatles?
Never mind. Tiago Serafim's reply answered my question for me. Follow on question: say I want to make a 2-dimensional table of the dates when people joined bands. I'd have code that looks like this. for p in Person.objects.all(): for g in Group.objects.all(): date = Membership.objects.get(person=p, group=g).join_date ... Am I making (person x group) database calls here? This is impression I get from reading: http://docs.djangoproject.com/en/dev/ref/models/querysets/#id1 Is this inefficient? Is there a way to do this with a single database call? On Sep 14, 11:43 am, "W.P. McNeill" <bill...@gmail.com> wrote: > Or maybe another way of asking this, since I don't want to force you > to write Python code just to answer my question... > > If I have the music group model written as shown in the Django > documentation is it possible to write a model API statement that gets > me this information, or would I have to add fields to the model? > > Thanks. > > On Sep 14, 9:46 am, Alexandru-Emil Lupu <gang.al...@gmail.com> wrote: > > > > > basically you would have to make a ManyToMany relation thru a class. In that > > class you make m,n,date field > > After that you just use a query to answer the question: Who (Paul)? joined > > to whom (Beatles), and after that will pop up the ManyToMany date field that > > will answer to question "when". > > > I am preety new in django my self .. and i don't know pretty well how to do > > it... > > > On Mon, Sep 14, 2009 at 6:21 PM, W.P. McNeill <bill...@gmail.com> wrote: > > > > I can't figure out how to query the values of fields in a ManyToMany > > > "through" table. > > > > For instance, say I'm working with the Beatles database in the Django > > > documentation (http://docs.djangoproject.com/en/dev/topics/db/models/ > > > #extra-fields-on-many-to-many-relationships<http://docs.djangoproject.com/en/dev/topics/db/models/%0A#extra-field...>). > > > I want to be able to > > > query the date on which Paul joined the Beatles. (As opposed to when > > > Ringo joined the Beatles, or when Paul joined Wings.) Basically I > > > want to treat the Group table as a two-dimensional array, look up: > > > > Group[Beatles][Paul].date_joined > > > > and have it return: > > > > date(1960, 8, 1) > > > > I'd think this would be easy to do, but I've been playing around with > > > the command-line database API and I can't figure it out. The > > > documentation I've seen describes how to use a Membership field as a > > > filter criteria, but not how to look up the actual value. > > > -- > > As programmers create bigger & better idiot proof programs, so the universe > > creates bigger & better idiots! > > I am on web: http://www.alecslupu.ro/ > > I am on twitter:http://twitter.com/alecslupu > > I am on linkedIn:http://www.linkedin.com/in/alecslupu > > Tel: (+4)0748.543.798 --~--~-~--~~~---~--~~ 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: When did Paul join the Beatles?
Or maybe another way of asking this, since I don't want to force you to write Python code just to answer my question... If I have the music group model written as shown in the Django documentation is it possible to write a model API statement that gets me this information, or would I have to add fields to the model? Thanks. On Sep 14, 9:46 am, Alexandru-Emil Lupu <gang.al...@gmail.com> wrote: > basically you would have to make a ManyToMany relation thru a class. In that > class you make m,n,date field > After that you just use a query to answer the question: Who (Paul)? joined > to whom (Beatles), and after that will pop up the ManyToMany date field that > will answer to question "when". > > I am preety new in django my self .. and i don't know pretty well how to do > it... > > > > > > On Mon, Sep 14, 2009 at 6:21 PM, W.P. McNeill <bill...@gmail.com> wrote: > > > I can't figure out how to query the values of fields in a ManyToMany > > "through" table. > > > For instance, say I'm working with the Beatles database in the Django > > documentation (http://docs.djangoproject.com/en/dev/topics/db/models/ > > #extra-fields-on-many-to-many-relationships<http://docs.djangoproject.com/en/dev/topics/db/models/%0A#extra-field...>). > > I want to be able to > > query the date on which Paul joined the Beatles. (As opposed to when > > Ringo joined the Beatles, or when Paul joined Wings.) Basically I > > want to treat the Group table as a two-dimensional array, look up: > > > Group[Beatles][Paul].date_joined > > > and have it return: > > > date(1960, 8, 1) > > > I'd think this would be easy to do, but I've been playing around with > > the command-line database API and I can't figure it out. The > > documentation I've seen describes how to use a Membership field as a > > filter criteria, but not how to look up the actual value. > > -- > As programmers create bigger & better idiot proof programs, so the universe > creates bigger & better idiots! > I am on web: http://www.alecslupu.ro/ > I am on twitter:http://twitter.com/alecslupu > I am on linkedIn:http://www.linkedin.com/in/alecslupu > Tel: (+4)0748.543.798 --~--~-~--~~~---~--~~ 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: When did Paul join the Beatles?
I'm afraid I didn't follow that. Do you have some simple Python examples? On Sep 14, 9:46 am, Alexandru-Emil Lupu <gang.al...@gmail.com> wrote: > basically you would have to make a ManyToMany relation thru a class. In that > class you make m,n,date field > After that you just use a query to answer the question: Who (Paul)? joined > to whom (Beatles), and after that will pop up the ManyToMany date field that > will answer to question "when". > > I am preety new in django my self .. and i don't know pretty well how to do > it... > > > > > > On Mon, Sep 14, 2009 at 6:21 PM, W.P. McNeill <bill...@gmail.com> wrote: > > > I can't figure out how to query the values of fields in a ManyToMany > > "through" table. > > > For instance, say I'm working with the Beatles database in the Django > > documentation (http://docs.djangoproject.com/en/dev/topics/db/models/ > > #extra-fields-on-many-to-many-relationships<http://docs.djangoproject.com/en/dev/topics/db/models/%0A#extra-field...>). > > I want to be able to > > query the date on which Paul joined the Beatles. (As opposed to when > > Ringo joined the Beatles, or when Paul joined Wings.) Basically I > > want to treat the Group table as a two-dimensional array, look up: > > > Group[Beatles][Paul].date_joined > > > and have it return: > > > date(1960, 8, 1) > > > I'd think this would be easy to do, but I've been playing around with > > the command-line database API and I can't figure it out. The > > documentation I've seen describes how to use a Membership field as a > > filter criteria, but not how to look up the actual value. > > -- > As programmers create bigger & better idiot proof programs, so the universe > creates bigger & better idiots! > I am on web: http://www.alecslupu.ro/ > I am on twitter:http://twitter.com/alecslupu > I am on linkedIn:http://www.linkedin.com/in/alecslupu > Tel: (+4)0748.543.798 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
When did Paul join the Beatles?
I can't figure out how to query the values of fields in a ManyToMany "through" table. For instance, say I'm working with the Beatles database in the Django documentation (http://docs.djangoproject.com/en/dev/topics/db/models/ #extra-fields-on-many-to-many-relationships). I want to be able to query the date on which Paul joined the Beatles. (As opposed to when Ringo joined the Beatles, or when Paul joined Wings.) Basically I want to treat the Group table as a two-dimensional array, look up: Group[Beatles][Paul].date_joined and have it return: date(1960, 8, 1) I'd think this would be easy to do, but I've been playing around with the command-line database API and I can't figure it out. The documentation I've seen describes how to use a Membership field as a filter criteria, but not how to look up the actual value. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Can all of unicode be slugified?
I am writing a Django application that uses characters from the International Phonetic Alphabet (IPA). I am trying to type the IPA characters into the admin interface and have Django automatically prepopulate a slug field. Django is ignoring the IPA characters. Is this expected behavior? I can see some discussion on the web that references unicode support for slugification, but I can't tell if that unicode support works for any arbitrary unicode characters, or Django has hand-crafted slugification for certain non-ASCII characters (e.g. common European characters). If the latter is the case, I will have to IPA slugs from something other than the IPA characters because these are probably too obscure to ever be included in Django API code. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Is slugify available as a Django API call?
I am going to populate the tables in my Django app from .CSV files rather than through the admin interface, so I am going to need a slugify Python function. I could write my own or pull a snippet from the web, but this seems error prone. The right way to do it would seem to be to use the slugify code that is already in Django. This code must be in there somewhere because there is a slugify template feature and the admin pages can prepopulate slug fields. However, I don't see a reference in the documentation to a slugify Python function that can be called from a Django app, and the fact that I can find lots of Django snippets online in which people are rolling their own slugify function makes me think that this function is not part of the Django API. What is the best way to slugify an arbitrary string using a Python call? --~--~-~--~~~---~--~~ 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: Can I dereference a field in the output of a filter?
The with tag worked. Thanks. On Sep 12, 12:10 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Sep 12, 8:08 pm, "W.P. McNeill" <bill...@gmail.com> wrote: > > > > > > > I have a view that renders a table. The "table" object is a list > > rows, which are themselves lists of model objects. These objects have > > a parameter called label. > > > Inside the template > > > {{ object.label }} > > > render's an objects label and > > > {{ row|first }} > > > renders the first object in the row. > > > I want to be able to render the label of the first object in the row. > > I want to write something like this > > > {{ row|first.label }} > > > but that doesn't work. Is there equivalent syntax that does work > > within the template markup language? > > You might be able to use the {% with %} tag to assign the first row to > another variable, and use that. Untested: > > {% with row|first as first_row %} > {{ first_row.label }} > {% endwith %} > > Otherwise, you'll need a custom template tag - luckily these are very > easy to write. > -- > DR. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Can I dereference a field in the output of a filter?
I have a view that renders a table. The "table" object is a list rows, which are themselves lists of model objects. These objects have a parameter called label. Inside the template {{ object.label }} render's an objects label and {{ row|first }} renders the first object in the row. I want to be able to render the label of the first object in the row. I want to write something like this {{ row|first.label }} but that doesn't work. Is there equivalent syntax that does work within the template markup language? --~--~-~--~~~---~--~~ 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: What is the correct database format for storing a 2-dimensional table?
1. The database schema you suggest is something I tried. I wasn't sure how to enforce my uniqueness requirements within it, but you may have answered that. 2. The uniqueness criteria is that the feature-phoneme pair is present only once. So using your schema I could have a FeaturePhoneme table that looks like like this: ... p LABIAL + p VOICED - w LABIAL + ... but not something that looks like this: ... p LABIAL + p LABIAL + p LABIAL - ... because the phoneme "p" must have a unique value for "LABIAL". The unique_together directive may be what I'm looking for. What are other places in the Django framework where you can specify uniqueness. Googling "Django" "unique" it looks like there are various unique directives you can attach to fields: http://docs.djangoproject.com/en/dev/ref/models/fields/#unique Are there others? 3. I'm not sure what a formset is but I can read about that in the documentation. Thanks. Because I'm new to Django I don't know the names of keywords like "unqiue_together" and "formset" that I should be searching for, so this is what I need. On Sep 10, 1:30 am, Vwrote: > On Sep 10, 12:18 am, "W.P.McNeill" wrote: > > > > > > > I am writing a Django app to store and manipulate a 2-dimensional > > table of data. I don't think I'm trying to do anything particularly > > difficult, but I'm new to both Django and relational databases, so I'm > > getting confused by various design considerations. I'm hoping there > > are canonical answers to the questions I ask below that will be > > obvious to people in this group. > > > The rows of the table are called "phonemes" and the columns are called > > "features". For a given phoneme, the features all take on the values > > +, -, or undefined. A feature value is specified only once for every > > phoneme. To make things more concrete, here is a Google spreadsheet > > representation of what I want: > > >http://spreadsheets.google.com/pub?key=t1WKdNNiy_JZgFLVui0XETA... > > > The funny-looking symbols are the names of the phonemes, and the all- > > caps words like SYLLABIC, STRESS, LONG etc. are features. (Sorry to > > bombard everyone with terminology from linguistics. I thought about > > translating to a more familiar problem domain, but decided I would > > just get myself more confused in the process.) > > > This is not apparent from the spreadsheet linked above, but to each of > > the phonemes and features I need to attach URIs that point to metadata > > stored elsewhere on the web. > > > A few questions: > > > 1. What is the correct database table design for this problem? > > I would do something like > > class Feature(models.Model): > feature = models.CharField > > class Phoneme(models.Model): > phoneme = models.CharField > feature = models.ManyToManyField(Feature, through="FeaturePhoneme") > > class FeaturePhoneme(models.Model): > feature = models.ForeignKey(Feature) > phoneme = models.ForeignKey(Phoneme) > value = models.NullBooleanField > > > 2. How much well-formedness validation (e.g. restricting values to > > +,-,undefined, ensuring there is only one feature per phoneme) can I > > get automatically from the database table design and how much do I > > have to write as code? > > I did not get this one, in your example table there are several +-is > in every column/row, so what does it mean there is only one feature > per phoneme? Does it meant that a feature-phoneme pair is present only > once? if so, then try unique_together=((feature, phoneme),) on the > last table's Meta class? > > > 3. What is the best way to get a spreadsheet-like user interface, > > where a user clicks on a cell in a table and is presented with a "+/-/ > > undefined" selection box? > > You might want to create a formset of FeaturePhoneme elements, but you > should present it in a different way than usual, might need plenty of > template work > > I've had a similar table structure that I exported the data to csv, > the relevant code segment is > athttp://bazaar.launchpad.net/~viktor-nagy/django-questions/trunk/annot... > in the export_survey_data method. > Here at the end you data variable is an array of ['Name', 'value1', > 'value2', ... ]. An extra line was needed for UTF-8 encoding, that you > might not need. > > just my two cents > > have a nice day > Viktor --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
What is the correct database format for storing a 2-dimensional table?
I am writing a Django app to store and manipulate a 2-dimensional table of data. I don't think I'm trying to do anything particularly difficult, but I'm new to both Django and relational databases, so I'm getting confused by various design considerations. I'm hoping there are canonical answers to the questions I ask below that will be obvious to people in this group. The rows of the table are called "phonemes" and the columns are called "features". For a given phoneme, the features all take on the values +, -, or undefined. A feature value is specified only once for every phoneme. To make things more concrete, here is a Google spreadsheet representation of what I want: http://spreadsheets.google.com/pub?key=t1WKdNNiy_JZgFLVui0XETA=html The funny-looking symbols are the names of the phonemes, and the all- caps words like SYLLABIC, STRESS, LONG etc. are features. (Sorry to bombard everyone with terminology from linguistics. I thought about translating to a more familiar problem domain, but decided I would just get myself more confused in the process.) This is not apparent from the spreadsheet linked above, but to each of the phonemes and features I need to attach URIs that point to metadata stored elsewhere on the web. A few questions: 1. What is the correct database table design for this problem? 2. How much well-formedness validation (e.g. restricting values to +,-,undefined, ensuring there is only one feature per phoneme) can I get automatically from the database table design and how much do I have to write as code? 3. What is the best way to get a spreadsheet-like user interface, where a user clicks on a cell in a table and is presented with a "+/-/ undefined" selection box? For question (1), I think I definitely want Phoneme and Feature tables, each of which have Name and URI fields. However, I'm uncertain what the relationship between these tables should be. I've tried various one-to-many, many-to-many, many-to-many-through-another- table configurations, and they all have their problems. I suspect the answer to (2) is that I can get all the validation out of the table design. For (3), I've only played with the admin interface so far. I don't know if its most Djangonic to use this or write my own views. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---