Extra attributes in model fields
I'd like to store extra attributes in the model fields so I can control the subsequent field-specific behavior from there. Let's say I have a model that stores metrics I then need to chart. In the view, I prefer not to have some logic that says: metrics = Metric.object.all() create_chart([metric.productivity for metric in metrics], "bar_chart") create_chart([metric.defects for metric in metrics], "pie_chart") I'd rather have something like: for metric_type in Metric.fields: create_chart([metric."metric_type" for metric in metrics], metric."metric_type".chart_type) The big advantage here is that I can add a new metrics element from the model without changing the view (Open-Close principle...) So it would be great if I could do something like: class Metric(models.Model): productivity = PositiveIntegerField( verbose_name = "the number of hot dogs we have produced during that period", chart_type = "bar_chart" ) ... However the model rejects fields it does not recognize. I tried creating my own doctored model to wrap the built-in models: class _PositiveIntegerField(models.fields.CharField): def __init__(self, *args, **kwargs): if "extra_attrs" in kwargs: self.extra_attrs = kwargs["extra_attrs"] del kwargs["extra_attrs"] models.fields.PositiveIntegerField.__init__(self, *args, **kwargs) This way I can do: class Metric(models.Model): productivity = _PositiveIntegerField( verbose_name = "the number of hot dogs we have produced during that period", extra_attrs = {'chart_type' : "bar_chart"} ) ... There are two problems here: 1. I'd need to wrap every field type 2. In the ModelForm I create from this model the type still registers as the built-in type: class MetricForm(models.ModelForm): class Meta: model = Metric >>> mf = MetricForm() >>> mf.fields['productivity'] Any suggestion as to how to design this right? --~--~-~--~~~---~--~~ 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: manage.py test without using a database?
On Wed, Dec 31, 2008 at 7:08 AM, Bo Shiwrote: > > Hi, > > One of our django applications does not use django's ORM. Is there a > way to run > > ./manage.py test my_app > > Such that it does not perform test database setup? There are two ways that you could do this. The first would be to define a custom test runner that skipped the database setup phase. django/test/simple/run_tests() will give you a model for what needs to be in a test runner; take a copy of this method (removing the database setup portions) and follow the instructions in [1] The second approach would be to define a dummy database backend that didn't complain about a database not being defined. django/db/backends/dummy gives you a starting point for this. Either way, you will need to make changes to your settings file. Neither of these approaches will fall in to the "if I'm only testing my_app, don't bother setting up the database, otherwise set up the database as normal" category. [1] http://docs.djangoproject.com/en/dev/topics/testing/#using-different-testing-frameworks 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 -~--~~~~--~~--~--~---
Re: SimpleDB Support
On Thu, Jan 1, 2009 at 3:21 AM, Travis Reederwrote: > > I've read some old threads discussing this, but I'm wondering if any > progress has been made? There certainly isn't anything official to report. Adding support for SimpleDB, CouchDB, Google AppEngine, HBase, or any other non-SQL data source is on the "nice to have" list, but not a current development priority of the core Django team. For a list of the current development priorities, see the v1.1 feature list [1] However, this is a volunteer project - if anyone wants to contribute a non-SQL data backend, we're only too happy for their contribution. If integrating a non-SQL backend requires changes to the Django core, we are willing to entertain any well explained proposal. [1] http://code.djangoproject.com/wiki/Version1.1Roadmap 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 -~--~~~~--~~--~--~---
Re: about templatetags
On Thu, Jan 1, 2009 at 8:18 AM, Alanwrote: > Happy new year List! > So, I have in a project several apps and they basically use the same > templatetags. I found out by luck that I just need to define it in one > application, something like: > app1/ > models.py > ... > app2/ > templatetags/mytags.py > models.py > ... > and app1 will use mytags. > Is my inference right? Well it's working here. If so, why templatetags has > to be inside apps folder? Why not at the same level of 'template' folder? > It sounds inconsistent to me, or I am probably missing something here. Your usage is correct i.e., you only need to define the template tag once. However, I'm a little confused as to why you see it as inconsistent. Templates will tend to be site/project specific, so it makes sense that templates aren't associated with the individual applications inside a project. Hence, projects tend to have a top level templates directory that are independent of the applications in use. Template Tags, on the other hand, are just blocks of code, so they need to be reusable. The unit of reusability in Django is the application. A template tag is defined as being part of App2, but that is really just a way of getting the template tag registered - it doesn't limit the places where the template tag can be used. The possible source of confusion is that there isn't any namespacing of template tags - there is only the single global templatetag namespace. Introducing namespaces for template tags is a subject that gets raised occasionally - search the archives and the ticket database if you want to see the state of play of that discussion. 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 -~--~~~~--~~--~--~---
in db/models/query.py - TypeError: 'exceptions.IndexError' object is not callable
I am having the following error sent to my email from a live site. I haven't been able to reproduce the error myself, but was hoping someone could point me in the right direction as to how to solve this. First of all, is it something in my code, or in Django? The last line of the traceback says Django, but I think it's probably something I'm doing. Any ideas? Thanks, Grant Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/django/core/handlers/ base.py", line 86, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/usr/lib/python2.5/site-packages/django/contrib/auth/ decorators.py", line 67, in __call__ return self.view_func(request, *args, **kwargs) File "/usr/local/src/wxcoder/observations/views.py", line 160, in enter if form.is_valid(): File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 120, in is_valid return self.is_bound and not bool(self.errors) File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 111, in _get_errors self.full_clean() File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 241, in full_clean self.cleaned_data = self.clean() File "/usr/local/src/wxcoder/observations/forms.py", line 104, in clean self.validate() File "/usr/local/src/wxcoder/observations/forms.py", line 462, in validate ]: validator(self.cleaned_data) File "/usr/local/src/wxcoder/observations/forms.py", line 257, in ValidateGrossLimit e = Element.objects.get(elementID=e_id) File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line 93, in get return self.get_query_set().get(*args, **kwargs) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 309, in get % self.model._meta.object_name) TypeError: 'exceptions.IndexError' object is not callable , POST:, COOKIES:{'__utma': '145837938.4275713312103283000.1230773473.1230773473.1230773473.1', '__utmb': '145837938.47.10.1230773473', '__utmc': '145837938', '__utmz': '145837938.1230773473.1.1.utmcsr=(direct)|utmccn=(direct)| utmcmd=(none)', 'sessionid': '2678e9af381ca6ae35cb0a020b6818fb', 'username': 'eklutna.waterplant'}, META:{'AUTH_TYPE': None, 'CONTENT_LENGTH': 0L, 'CONTENT_TYPE': None, 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/ vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms- application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*', 'HTTP_ACCEPT_LANGUAGE': 'en-us', 'HTTP_CONNECTION': 'Keep-Alive', 'HTTP_CONTENT_LENGTH': '166', 'HTTP_CONTENT_TYPE': 'application/x-www-form-urlencoded', 'HTTP_COOKIE': 'sessionid=2678e9af381ca6ae35cb0a020b6818fb; __utma=145837938.4275713312103283000.1230773473.1230773473.1230773473.1; __utmb=145837938.47.10.1230773473; __utmc=145837938; __utmz=145837938.1230773473.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd= (none); username=eklutna.waterplant', 'HTTP_HOST': 'wxcoder.org', 'HTTP_PRAGMA': 'no-cache', 'HTTP_REFERER': 'http://wxcoder.org/wxcoder/observations/enter/? date=20081207', 'HTTP_UA_CPU': 'x86', 'HTTP_USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)', 'HTTP_VIA': '1.0 AWWUPROX3', 'PATH_INFO': u'/wxcoder/observations/enter/', 'PATH_TRANSLATED': None, 'QUERY_STRING': None, 'REMOTE_ADDR': '209.112.193.38', 'REMOTE_HOST': None, 'REMOTE_IDENT': None, 'REMOTE_USER': None, 'REQUEST_METHOD': 'POST', 'SCRIPT_NAME': '', 'SERVER_NAME': 'wxcoder.org', 'SERVER_PORT': 0, 'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_SOFTWARE': 'mod_python'}> --~--~-~--~~~---~--~~ 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: Model fields and arrays?
On Wed, Dec 31, 2008 at 6:02 AM, bruno desthuilliers < bruno.desthuilli...@gmail.com> wrote: > > > > On 31 déc, 05:40, schwimwrote: > > I'm trying to build a model that will store the counts of each of 10 > > possible choices, e.g.: > > > > v1 = models.IntegerField(default=0) > > v2 = models.IntegerField(default=0) > > v3 = models.IntegerField(default=0) > > ... > > v10 = models.IntegerField(default=0) > > > > I'd prefer to represent this as an array > > Where ? > > > rather than 10 separate > > fields. I looked at the CommaSeparatedIntegerField as an alternative, > > but I want to explicitly state that there are 10 entries available per > > instance. > > Note that at the Python level, a list (I suppose that's what you mean > by 'array') is not fixed-length. Yes, that is what I meant actually. I'm new to python, a perl convert I guess you could say. > > > If all you want is a way to access the values as a sequence (read- > only) from your python/templates code, it's just a matter of adding a > simple property: > > > class YourModel(models.Model): ># you code here >@property >def values(self): >return [getattr(self, "v%s" % i) for i in range(1,11)] > > > then: > > m = YourModel.objects.get(...) > m.values > m.values[0] > m.values[9] Yes, I think this would work nicely actually. I really only need to access the values as a list when reading. Writes will be specific. > > > > If you want a reliable read-write property, this becomes a bit more > involved. You have to write a custom descriptor returning a custom > sequence type that retains a reference on the model instance. > > The following code should get you started - warning: it's Q, full of > magic numbers, not generic, not factorized, and not even tested. > IOW : it's by no mean production code. > > class MySequence(object): >def __init__(self, model): >self._model = model > >def _as_fieldname(self, index): ># sequences are zero-based ># XXX : magic number >if not 0 <= index <= 9: >raise IndexError ># your fields are 1-based ># XXX duplicated in MySequenceDescriptor >return "v%s" % (index+1) > >def __getitem__(self, index): >fname = self._as_fieldname(index) >return getattr(self._model, fname) > >def __setitem__(self, index, value): >fname = self._as_fieldname(index) >setattr(self._model, fname, value) > ># you may need some other sequence __magicmethods__ here ># check the Python's manual about emulating sequence types > > > class MySequenceDescriptor(object): >def __get__(self, instance, cls): >if instance is None: ># looked up in the class >return self ># looked up on a model instance: >return MySequence(instance) > >def __set__(self, instance, value): ># expects a sequence of len(10) ># XXX : magic number >if len(value) != 10: >raise ValueError("yadda yadda") >for index, val in enumerate(value): ># XXX duplication of MySequence._as_fieldname >setattr(instance, "v%s" % (index+1), val) > > > class YourModel(models.Model): ># your code here > >values = MySequenceDescriptor() > > HTH > > Very helpful, yes, thank you. I think I understand your approach here, but it's probably more complicated than I need. --~--~-~--~~~---~--~~ 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: NetBeans IDE for Python
actually, it looks like one has to build netbeans from source... not being a java person, how dif ficult can this be? I'm trying: hg clone http://hg.netbeans.org/main/ But it's taking forever. I've gotta sleep; will check tomorrow :) On Nov 28 2008, 6:48 pm, Ovnicraftwrote: > 2008/11/27 itsnotvalid > > > > > It says for requesting username as password to access. Did I miss > > anything here? > > try guest:guest > > > > > > > On Nov 27, 11:14 pm, Ovnicraft wrote: > > > 2008/11/27 AndyB > > > > > More to the point - has anyone figured out how to! I couldn't even > > > > find a dowload or repository link for the Django branch. > > > > > On Nov 27, 2:21 pm, Robin wrote: > > > > > hello, > > > > > > I have also installed it and have seen there is this branch: > > > >http://wiki.netbeans.org/Python#section-Python-DjangoBranch > > > > > > anybody has installed this version of the branch ? > > > > svn checkouthttps://nbpython.dev.java.net/svn/nbpython/branches/django > > > > > > r > > > > > > On Nov 20, 8:04 pm, ohmi wrote: > > > > > > > Same results here although other sorts of autocomplete to seem to > > be > > > > > > somewhat functional. > > > > > > No django-specific documentation yet, like how to set up the > > debugging > > > > > > environment. > > > > > > It looks like this stuff is being done according to their roadmap. > > > > > > > Could be a great platform, esp. considering the price. > > > > > > > O > > > > > > > On Nov 20, 5:01 am, lig wrote: > > > > > > > > On 19 нояб, 21:22, Delta20 wrote: > > > > > > > > > NetBeans for Python has been released and based on the NB > > Python > > > > > > > > roadmap, it looks interesting for those of us working with > > Django. > > > > I > > > > > > > > haven't had much of a chance to play with it yet since it just > > came > > > > > > > > out today, but here's the info for anyone interested: > > > > > > > > > NetBeans IDE for Python: > > > >http://download.netbeans.org/netbeans/6.5/python/ea/ > > > > > > > > NB Python Roadmap:http://wiki.netbeans.org/Python > > > > > > > > from django.db import models > > > > > > > > class Page(models.Model): > > > > > > > name = models. # hitting Ctrl+Space here don't show field > > type > > > > > > > suggestions or anything from imported models package > > > > -- > > > [b]question = (to) ? be : !be; .[/b] > > -- > [b]question = (to) ? be : !be; .[/b] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
tagging in Practical Django Projects
Hi there. I'm still reading this book. I have almost all the templates done for the blog, but I'm stuck on tagging templates. I noticed that with the link_detail view that the bit of code {% if object.tags.count %} was not evaluating to TRUE even though tags were associated with the object. This resulted in "This link doesn't have any tags." appearing on every page for a link detail. I thought maybe once I finished the tagging templates I could resolve this, but I don't know how to call up a URL for a tag so that it will give a list of links or entries that tag associates. IOW, in my tag_list.html file I have this bit of code: {% block content %} {% for tag in object_list %} {{ tag.name }} {% endfor %} {% endblock %} This displays the full list of tag names, but I have no idea what anchor to use on them to get the entries or links by tag. Sorry if this sounds pretty dumb. But I have been using a few websites to help me answer questions and problems that crop up, like Hedged Down, but none of those websites seem to have encountered this problem. 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: NetBeans IDE for Python
Ok, I have checked out the code. Now, where do I put it? And how do I use it? I put it inside the netbeans folder, but nothing seems to have changed. Should I see a 'django project' option anywhere? Thanks On Nov 28 2008, 6:48 pm, Ovnicraftwrote: > 2008/11/27 itsnotvalid > > > > > It says for requesting username as password to access. Did I miss > > anything here? > > try guest:guest > > > > > > > On Nov 27, 11:14 pm, Ovnicraft wrote: > > > 2008/11/27 AndyB > > > > > More to the point - has anyone figured out how to! I couldn't even > > > > find a dowload or repository link for the Django branch. > > > > > On Nov 27, 2:21 pm, Robin wrote: > > > > > hello, > > > > > > I have also installed it and have seen there is this branch: > > > >http://wiki.netbeans.org/Python#section-Python-DjangoBranch > > > > > > anybody has installed this version of the branch ? > > > > svn checkouthttps://nbpython.dev.java.net/svn/nbpython/branches/django > > > > > > r > > > > > > On Nov 20, 8:04 pm, ohmi wrote: > > > > > > > Same results here although other sorts of autocomplete to seem to > > be > > > > > > somewhat functional. > > > > > > No django-specific documentation yet, like how to set up the > > debugging > > > > > > environment. > > > > > > It looks like this stuff is being done according to their roadmap. > > > > > > > Could be a great platform, esp. considering the price. > > > > > > > O > > > > > > > On Nov 20, 5:01 am, lig wrote: > > > > > > > > On 19 нояб, 21:22, Delta20 wrote: > > > > > > > > > NetBeans for Python has been released and based on the NB > > Python > > > > > > > > roadmap, it looks interesting for those of us working with > > Django. > > > > I > > > > > > > > haven't had much of a chance to play with it yet since it just > > came > > > > > > > > out today, but here's the info for anyone interested: > > > > > > > > > NetBeans IDE for Python: > > > >http://download.netbeans.org/netbeans/6.5/python/ea/ > > > > > > > > NB Python Roadmap:http://wiki.netbeans.org/Python > > > > > > > > from django.db import models > > > > > > > > class Page(models.Model): > > > > > > > name = models. # hitting Ctrl+Space here don't show field > > type > > > > > > > suggestions or anything from imported models package > > > > -- > > > [b]question = (to) ? be : !be; .[/b] > > -- > [b]question = (to) ? be : !be; .[/b] --~--~-~--~~~---~--~~ 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: specify alternative settings.py file at startup
On Wed, Dec 31, 2008 at 11:45 AM, dick...@gmail.comwrote: > > i'm confused on the --settings option on manage.py. > > if i have a project call foo, i'd have in ./foo/settings.py > > to run: python manage.py runserver 8080 > > let's say i have a bar.settings.py which contains different values > (like test database to use or something), i'm trying to run: > > python manage.py runserver --settings=bar.settings 8080 (and maybe > combintations of), but keep getting some derivations of: "Could Not > Import settings...is it on the sys.path, no module named bar.settings. The cause of the confusion here is the name of your settings file. Python uses dot notation to specify module hierarchies. When you specify bar.settings, Python expects to find a directory named bar with a file called settings.py in that directory. If you rename your settings file bar_settings.py (or something else that is compatible with Python module naming) you should stop getting the error you report. 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 -~--~~~~--~~--~--~---
about templatetags
Happy new year List! So, I have in a project several apps and they basically use the same templatetags. I found out by luck that I just need to define it in one application, something like: app1/ models.py ... app2/ templatetags/mytags.py models.py ... and app1 will use mytags. Is my inference right? Well it's working here. If so, why templatetags has to be inside apps folder? Why not at the same level of 'template' folder? It sounds inconsistent to me, or I am probably missing something here. Many thanks in advance. -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Outdated data in django page rendering w/ cacheing disabled
I have a django project which will be taking data from a db that is already being managed and maintained by another set of programs and read it and display it for reporting and for determineing possible problems and then in some cases making changes back into the system through other means (not by making changes to db) I have created a set of functions and classes to connect to the db and request the data and then display the data rendered as a page, however what I'm finding is that when the data is being changed from the main set of applications connecting to and using this db and then i refresh my browser django is still displaying old data in some cases, now I've looked through all the cacheing documentation and as far as I can find I've disabled all cacheing and I know it's not the browsers' cacheing because when I telnet and request the pages it's comeing back as the old data not the new data, and if I run the python code outside of django just to output the data I'm passing into the templates it's updating timely in my views.py for the particular pages in question I have from django.views.decorators.cache import never_cache @never_cache def index(request): before every function for rendering data in my settings.py I have MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', ) TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', ) I removed every thing that I thought wasn't needed for this situation to make sure there isn't anything I'm missing that could cause this As far as I can tell there is no reason for this data to be outdated on browser refresh, I've tried looking through the documentation and other places to find what could be causing this Any Ideas? --~--~-~--~~~---~--~~ 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: FormWizard: Setting up a ChoiceField.choices based on previous forms,
On Tue, Dec 30, 2008 at 3:16 PM, Ariel Mauricio Nunez Gomezwrote: > Hello list, > Today I started using FormWizard and could not find a clean way to populate > a choices field based on previously submitted forms, I ended up overriding > the render method like this(The only changed line is the one highlited): If you're doing a lot of FormWizard work, maybe take a look at the Session-based FormWizard I wrote and give me some feedback. http://code.djangoproject.com/ticket/9200 It sounds like you have a reasonable solution to your issue, but I thought I'd go ahead and solicit some feedback anyway, and maybe this class I wrote could benefit you some. Thanks, 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ROOT_URLCONF
On Dec 31, 12:31 pm, "dick...@gmail.com"wrote: > was looking for some info on how ROOT_URLCONF setting is supposed to > be used? i am trying something very simple. i have a single django > project. there are two apps. > > i want to run one app, call it foo, with a specific settings file, > and set of urls, and bar with something else. > > so, with a myproject/settings.py, myproject/bar-settings.py, > myproject/urls.py , myproject/bar-urls.py > > bar-settings.py has ROOT_URLCONF=myproject.bar-urls > everything works great with the foo (default project). > > now to run the "bar" project, i start it: python manage.py runserver -- > settings=bar-settings > > the error i get is, after i hit a url (everything starts up fine): > > File "/Users/rich/devtools/jython-dev/dist/Lib/site-packages/django/ > core/urlresolvers.py", line 246, in resolve > return get_resolver(urlconf).resolve(path) > File "/Users/rich/devtools/jython-dev/dist/Lib/site-packages/django/ > core/urlresolvers.py", line 179, in resolve > for pattern in self.urlconf_module.urlpatterns: > File "/Users/rich/devtools/jython-dev/dist/Lib/site-packages/django/ > core/urlresolvers.py", line 198, in _get_urlconf_module > self._urlconf_module = __import__(self.urlconf_name, {}, {}, ['']) > ImportError: No module named bar I think your problem is that 'bar-settings' is not a valid identifier in Python. You can't use a hyphen in names of variables or modules. Try calling them bar_settings etc, and see if that works. -- 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 -~--~~~~--~~--~--~---
[job] freelance django developer needed
We are currently looking for a Django developer or two to join us on a freelance basis. Our "mission", replyforall.com, is ready for the next phase and we're looking for some additional developer bandwidth to help us take it there. Our current need is more slanted towards a backend web developer/ engineer. Depending on your skills, we'll probably start you off with some customized reporting in the django admin to see how things work out and then ask for more site-specific work once you become more familiar with our project and we see where your skills are. This is telecommute/work from home, so you should be able to work independently, but also be able to demonstrate effective people and time management skills, so as to deliver work within our deadlines. Location is pretty irrelevant as long as you have decent Internet access, chat and email. Our current team includes people from New York, San Francisco, Portland and Argentina. If you're interested please send us your daily/hourly rates, your availability as well as a few words about your programming background and experience with Django. We'll also need samples/URLs of past projects, completed or still pending. Any questions? Feel free to email me. --~--~-~--~~~---~--~~ 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: Using ModelChoiceField with query set - no error but no list either
Thanks that makes sense. I'll give it go. Happy New Years --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
SimpleDB Support
I've read some old threads discussing this, but I'm wondering if any progress has been made? Cheers, Travis --~--~-~--~~~---~--~~ 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: form validation does not work
Thanks for the reference. The problem is solved with this code modification: def contact(request): if request.method == 'POST': f = ContactForm(request.POST) if f.is_valid(): email = f.cleaned_data['email'] ... #send email return HttpResponseRedirect(reverse('contact_success')) else: f=ContactForm() return render_to_response( 'post_contact.html', { 'form':f }, context_instance = RequestContext(request) ) On Dec 31, 12:36 pm, Daniel Rosemanwrote: > On Dec 31, 12:18 am, Chuck22 wrote: > > > > > > > class ContactForm(forms.Form): > > email = forms.EmailField(required=True, > > widget=forms.TextInput(attrs= > > {'size':'30'}), > > error_messages={'required':'Please fill > > out your Email'}) > > ... > > > in my form html file: > > ... > > label for="id_full_name">Your email address > > {{ form.email.errors }} > > {{ form.email }} > > ... > > > in my view: > > def contact(request): > > if request.method == 'POST': > > f = ContactForm(request.POST) > > if f.is_valid(): > > email = f.cleaned_data['email'] > > ... > > return HttpResponseRedirect(reverse('contact_success')) > > > When user submit the contact form without fill out email field, the > > form get submitted without displaying error message 'Please fill out > > your Email'. Instead, I got error: The view app.views.contact didn't > > return an HttpResponse object. > > > it seems f.is_valud return false, which is correct. But I think form > > validation should kick in at this point and return error message to > > {{ form.email.errors }} field in template. Why doesn't the validation > > work? Did I miss anything? > > As Alex says, we'll need to see the full view function to really help. > But assuming the last line what you've posted is actually the last > line of the function, you are indeed missing something - the code to > return something if the form fails validation. > > The error message you've posted tells you exactly what's happening - > your view is not returning an HttpResponse. It's always your > responsibility to do this - Django won't ever do something by default > (except 404 and 500 errors). Look more closely at the example given in > the > documentation:http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-... > You'll see that in that view, the return at the end is called in both > the case of the initial GET, and if the POST failed validation. > -- > DR.- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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: form validation does not work
On Dec 31, 12:18 am, Chuck22wrote: > class ContactForm(forms.Form): > email = forms.EmailField(required=True, > widget=forms.TextInput(attrs= > {'size':'30'}), > error_messages={'required':'Please fill > out your Email'}) > ... > > in my form html file: > ... > label for="id_full_name">Your email address > {{ form.email.errors }} > {{ form.email }} > ... > > in my view: > def contact(request): > if request.method == 'POST': > f = ContactForm(request.POST) > if f.is_valid(): > email = f.cleaned_data['email'] > ... > return HttpResponseRedirect(reverse('contact_success')) > > When user submit the contact form without fill out email field, the > form get submitted without displaying error message 'Please fill out > your Email'. Instead, I got error: The view app.views.contact didn't > return an HttpResponse object. > > it seems f.is_valud return false, which is correct. But I think form > validation should kick in at this point and return error message to > {{ form.email.errors }} field in template. Why doesn't the validation > work? Did I miss anything? As Alex says, we'll need to see the full view function to really help. But assuming the last line what you've posted is actually the last line of the function, you are indeed missing something - the code to return something if the form fails validation. The error message you've posted tells you exactly what's happening - your view is not returning an HttpResponse. It's always your responsibility to do this - Django won't ever do something by default (except 404 and 500 errors). Look more closely at the example given in the documentation: http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view You'll see that in that view, the return at the end is called in both the case of the initial GET, and if the POST failed validation. -- 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 -~--~~~~--~~--~--~---
Re: form validation does not work
def contact(request): if request.method == 'POST': f = ContactForm(request.POST) if f.is_valid(): email = f.cleaned_data['email'] ... #send email return HttpResponseRedirect(reverse('contact_success')) else: f=ContactForm() return render_to_response( 'post_contact.html', { 'form':f }, context_instance = RequestContext(request) ) I am still workong on the view code to send email when users submit the form. The problem is that required field did not validate and block the form submission. User is able to submit the form without providing email which is a required field. On Dec 31, 1:50 am, "Alex Koshelev"wrote: > Please post here entire view code > > > > On Wed, Dec 31, 2008 at 8:18 AM, Chuck22 wrote: > > > class ContactForm(forms.Form): > > email = forms.EmailField(required=True, > > widget=forms.TextInput(attrs= > > {'size':'30'}), > > error_messages={'required':'Please fill > > out your Email'}) > > ... > > > in my form html file: > > ... > > label for="id_full_name">Your email address > > {{ form.email.errors }} > > {{ form.email }} > > ... > > > in my view: > > def contact(request): > > if request.method == 'POST': > > f = ContactForm(request.POST) > > if f.is_valid(): > > email = f.cleaned_data['email'] > > ... > > return HttpResponseRedirect(reverse('contact_success')) > > > When user submit the contact form without fill out email field, the > > form get submitted without displaying error message 'Please fill out > > your Email'. Instead, I got error: The view app.views.contact didn't > > return an HttpResponse object. > > > it seems f.is_valud return false, which is correct. But I think form > > validation should kick in at this point and return error message to > > {{ form.email.errors }} field in template. Why doesn't the validation > > work? Did I miss anything?- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ROOT_URLCONF
was looking for some info on how ROOT_URLCONF setting is supposed to be used? i am trying something very simple. i have a single django project. there are two apps. i want to run one app, call it foo, with a specific settings file, and set of urls, and bar with something else. so, with amyproject/settings.py, myproject/bar-settings.py, myproject/urls.py , myproject/bar-urls.py bar-settings.py has ROOT_URLCONF=myproject.bar-urls everything works great with the foo (default project). now to run the "bar" project, i start it: python manage.py runserver -- settings=bar-settings the error i get is, after i hit a url (everything starts up fine): File "/Users/rich/devtools/jython-dev/dist/Lib/site-packages/django/ core/urlresolvers.py", line 246, in resolve return get_resolver(urlconf).resolve(path) File "/Users/rich/devtools/jython-dev/dist/Lib/site-packages/django/ core/urlresolvers.py", line 179, in resolve for pattern in self.urlconf_module.urlpatterns: File "/Users/rich/devtools/jython-dev/dist/Lib/site-packages/django/ core/urlresolvers.py", line 198, in _get_urlconf_module self._urlconf_module = __import__(self.urlconf_name, {}, {}, ['']) ImportError: No module named bar --~--~-~--~~~---~--~~ 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: Model fields and arrays?
On Dec 30, 11:40 pm, schwimwrote: > I'm trying to build a model that will store the counts of each of 10 > possible choices, e.g.: > > v1 = models.IntegerField(default=0) > v2 = models.IntegerField(default=0) > v3 = models.IntegerField(default=0) > ... > v10 = models.IntegerField(default=0) > > I'd prefer to represent this as an array rather than 10 separate > fields. I looked at the CommaSeparatedIntegerField as an alternative, > but I want to explicitly state that there are 10 entries available per > instance. > > Any suggestions on how this can be done, or perhaps a better way to > solve this puzzle? I have a snippet here: http://www.djangosnippets.org/snippets/1200/ which defines a custom model field and accompanying form field to store a list of values. It doesn't currently have an option to set a maximum number of items in the model field, just in the form field, but that could probably be added fairly easily. -- 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 -~--~~~~--~~--~--~---
Re: Using ModelChoiceField with query set - no error but no list either
On Dec 31, 11:13 am, phoebebrightwrote: > I have a model that has a car and a car has a foreign key to carmodel > via the field model (too many models!) > > This is the line for the form which appears to run: > > carmodel=forms.ModelChoiceField(queryset=Car.objects.all().values > ('model','model__name').distinct() ) > > It generates the correct SQL > > SELECT DISTINCT `carpoint_car`.`model_id`, `carpoint_carmodel`.`name` > FROM `carpoint_car` INNER JOIN `carpoint_carmodel` ON > (`carpoint_car`.`model_id` = `carpoint_carmodel`.`id`) > > and if I run this manually I get 6 records returned: > > 6 Galaxy > 7 Bigun > 8 Touring > 9 Espace > 10 D1 > 11 Tank > > But I don't get the form being displayed. If I remove this line the > form displays okay. > > What pattern is ModelChoiceField expecting in the queryset to know > what fields to use to generate a choice from? You don't need the values() part. Django will use the id and the __unicode__ method or a normal queryset to generate the choices. If you want something different, use a standard integer field with a Select widget, and populate the choices manually. -- 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 -~--~~~~--~~--~--~---
Re: Calendar
On Wed, Dec 31, 2008 at 9:35 AM, Mariowrote: > > Karen, > > Can you provide me an example of the widget implementation? > Sorry, I am not sure what you are asking for. Someone said (I thought) that they wanted to have calendar inputs like the admin uses, only in their own pages, so I pointed to the doc that mentions where the admin widgets are located in the django source tree. They then said they "do now" (I assume that was meant to be "do not") want to use a widget, so I am not sure what the original question was asking for. The admin uses custom widgets, if you don't want to use widgets than you don't really want what the admin uses (and you're apparently not using Django forms, since Django forms use widgets?). Perhaps the objection to the admin widgets is that they use javascript, I'm not sure, since the response to my pointing to the doc was not at all clear to me. Anyway, if you want calendar inputs like the admin uses, it should be fairly straightforward to re-use the admin widgets that the doc mentions in your own pages, though you may need to look at the source to get the right names to specify for the widgets, I don't see that the doc details that. Personally I have not done this myself and don't have time at the moment to do any more with it than point at the existing doc. Karen > > On Dec 30, 9:30 am, "Karen Tracey" wrote: > > On Tue, Dec 30, 2008 at 7:51 AM, Praveen >wrote: > > > > > > > > > Hi All, > > > I want to use calendar in my html template as the default admin > > > interface uses. > > > > http://docs.djangoproject.com/en/dev/topics/forms/media/#form-media > > > > 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 -~--~~~~--~~--~--~---
Using ModelChoiceField with query set - no error but no list either
I have a model that has a car and a car has a foreign key to carmodel via the field model (too many models!) This is the line for the form which appears to run: carmodel=forms.ModelChoiceField(queryset=Car.objects.all().values ('model','model__name').distinct() ) It generates the correct SQL SELECT DISTINCT `carpoint_car`.`model_id`, `carpoint_carmodel`.`name` FROM `carpoint_car` INNER JOIN `carpoint_carmodel` ON (`carpoint_car`.`model_id` = `carpoint_carmodel`.`id`) and if I run this manually I get 6 records returned: 6 Galaxy 7 Bigun 8 Touring 9 Espace 10 D1 11 Tank But I don't get the form being displayed. If I remove this line the form displays okay. What pattern is ModelChoiceField expecting in the queryset to know what fields to use to generate a choice from? --~--~-~--~~~---~--~~ 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: Calendar
Karen, Can you provide me an example of the widget implementation? _Mario On Dec 30, 9:30 am, "Karen Tracey"wrote: > On Tue, Dec 30, 2008 at 7:51 AM, Praveen > wrote: > > > > > Hi All, > > I want to use calendar in my html template as the default admin > > interface uses. > > http://docs.djangoproject.com/en/dev/topics/forms/media/#form-media > > 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: Installing Django 1.0.2...
On Wed, Dec 31, 2008 at 9:20 AM, Peterwrote: > > Python cannot find django/utils/version.py. Usually everything needed > for > to run django (which is everything in the 'django' folder) is put > under the folder 'site-packages' > in your pythin installation. AFAIK simply copying C:\Django-1.0.2-final > \django to site-packages\django > should work. > The command that is failing here is "python setup.py install". It should not be necessary to copy anything to site-packages prior to running the install command. Karen > -- Peter > > On Dec 31, 8:46 am, mic wrote: > > I am a first time python/django user.. > > > > Running "python setup.py install" from django-1.0.2-final directory > > gives me this error > > > > Traceback (most recent call last): > > File "setup.py", line 69, in > > version = __import__('django').get_version() > > File "C:\Django-1.0.2-final\django\__init__.py", line 13, in > > get_version > > from django.utils.version import get_svn_revision > > ImportError: No module named utils.version > > > > Any ideas on what I am missing? > > > > Thanks > > > > Mic > > > --~--~-~--~~~---~--~~ 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: Installing Django 1.0.2...
Python cannot find django/utils/version.py. Usually everything needed for to run django (which is everything in the 'django' folder) is put under the folder 'site-packages' in your pythin installation. AFAIK simply copying C:\Django-1.0.2-final \django to site-packages\django should work. -- Peter On Dec 31, 8:46 am, micwrote: > I am a first time python/django user.. > > Running "python setup.py install" from django-1.0.2-final directory > gives me this error > > Traceback (most recent call last): > File "setup.py", line 69, in > version = __import__('django').get_version() > File "C:\Django-1.0.2-final\django\__init__.py", line 13, in > get_version > from django.utils.version import get_svn_revision > ImportError: No module named utils.version > > Any ideas on what I am missing? > > Thanks > > Mic --~--~-~--~~~---~--~~ 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: Installing Django 1.0.2...
On Wed, Dec 31, 2008 at 3:36 AM, micwrote: > > I am a first time python/django user > > running "python setup.py install" gives me this error > > Traceback (most recent call last): > File "setup.py", line 69, in >version = __import__('django').get_version() > File "C:\Django-1.0.2-final\django\__init__.py", line 13, in > get_version >from django.utils.version import get_svn_revision > ImportError: No module named utils.version > > Any help is appreciated. > > Thanks for the help. > That's odd. Do you have the files: C:\Django-1.0.2-final\django\utils\__init__.py C:\Django-1.0.2-final\django\utils\version.py If not, something has gone wrong with unpacking the 1.0.2 tarfile because those files are in it. If you do have those files, what version of Python are you using? 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: Inline problem in Postgres but not MySQL
I just installed 1.0.2 final and the bug has been fixed in that. -- Peter --~--~-~--~~~---~--~~ 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: Writing your first Django app
Thank you for the response. Good explanation Briel. Turned out I was loading the wrong URL but start to get an understanding for how Django works now. (I think!) till Django 2008/12/29 Briel> > The quick answer: > This goes into views.py (copied from the tutorial). > > def detail(request, poll_id): >return HttpResponse("You're looking at poll %s." % poll_id) > > Now to understand what happens a bit better: > In your views.py file you can make as many "def something(request):" > as you like. This is where you write your code to handle what or how > you'll make some http response. In your urls.py you write what model > in your views.py need to handle what urls. So when you write an url, > Django will find out if that is a valid url, comparing to the urls you > have in your urls.py file(s). If there is a match, then it will run > the model in your views file. > > In the code from the tutorial, 'mysite.polls.views.detail' will run > the above code, if it's written in the views.py in your polls app. It > returns a simple http response, a text string: "You're looking at poll > %s." % poll_id. The poll_id varible is gotten from the url. > > -Briel > > > johan skrev: > > yes of course my bad! > > > > http://docs.djangoproject.com/en/dev/intro/tutorial03/#intro-tutorial03 > > > > > > > > 2008/12/29 Abdel Bolanos Martinez > > > > > send me the url of the tutorial where you are, now!!! > > > > > > > > > On Mon, 2008-12-29 at 06:19 -0800, kallep wrote: > > > > > > that was a fast reply :) > > > > > > In part 3 I do not understand if I'm suppose to create a new view > > > called detail.py or if this code should be in to the views.py. The > > > problem is that I cant load the detail page or even figure out if I'm > > > supposed to be able to do that. I do not know what I'm building here! > > > > > > On Dec 29, 10:02 pm, Abdel Bolanos Martinez > > > wrote: > > > > what you have just done until now ??? > > > > > > > > On Mon, 2008-12-29 at 05:52 -0800, kallep wrote: > > > > > This is my first question here. I find it extremely difficult to > > > > > follow the "Writing your first Django app tutorial". I'm now > stocked > > > > > on the third part. Is it possible to see the finished source code > > > > > somewhere? The main difficulty is to understand what code are > > > > > supposed to go where. > > > > > > > > Abdel Bola�os Mart�nez > > > > Ing. Inf�rmatico > > > > Telf. 266-8562 > > > > 5to piso, oficina 526, Edificio Beijing, Miramar Trade Center. ETECSA > > > > > > > > > > > > > > > Abdel Bola�os Mart�nez > > > Ing. Inf�rmatico > > > Telf. 266-8562 > > > 5to piso, oficina 526, Edificio Beijing, Miramar Trade Center. ETECSA > > > > > > > > > > > --~--~-~--~~~---~--~~ 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: Model fields and arrays?
On 31 déc, 05:40, schwimwrote: > I'm trying to build a model that will store the counts of each of 10 > possible choices, e.g.: > > v1 = models.IntegerField(default=0) > v2 = models.IntegerField(default=0) > v3 = models.IntegerField(default=0) > ... > v10 = models.IntegerField(default=0) > > I'd prefer to represent this as an array Where ? > rather than 10 separate > fields. I looked at the CommaSeparatedIntegerField as an alternative, > but I want to explicitly state that there are 10 entries available per > instance. Note that at the Python level, a list (I suppose that's what you mean by 'array') is not fixed-length. At the relational (SQL) level, you could use a joined table storing values (yourmodel_id, numchoice, value) with yourmodel_id + numchoice as primary key (or, given Django's ORM limitation, using a unique (yourmodel_id, numchoice) constraint), but you'll have to add your own validation stuff (both at the database level and Django code level) to make sure numchoice is between 1 and 10. Now weither this is the right thing to do depends on the probabilities that you will want more than 10 "values" anytime soon. if this requirement is really stable, your current solution is ok to me (purist DBAs would probably run away screaming, but that's another problem). If all you want is a way to access the values as a sequence (read- only) from your python/templates code, it's just a matter of adding a simple property: class YourModel(models.Model): # you code here @property def values(self): return [getattr(self, "v%s" % i) for i in range(1,11)] then: m = YourModel.objects.get(...) m.values m.values[0] m.values[9] If you want a reliable read-write property, this becomes a bit more involved. You have to write a custom descriptor returning a custom sequence type that retains a reference on the model instance. The following code should get you started - warning: it's Q, full of magic numbers, not generic, not factorized, and not even tested. IOW : it's by no mean production code. class MySequence(object): def __init__(self, model): self._model = model def _as_fieldname(self, index): # sequences are zero-based # XXX : magic number if not 0 <= index <= 9: raise IndexError # your fields are 1-based # XXX duplicated in MySequenceDescriptor return "v%s" % (index+1) def __getitem__(self, index): fname = self._as_fieldname(index) return getattr(self._model, fname) def __setitem__(self, index, value): fname = self._as_fieldname(index) setattr(self._model, fname, value) # you may need some other sequence __magicmethods__ here # check the Python's manual about emulating sequence types class MySequenceDescriptor(object): def __get__(self, instance, cls): if instance is None: # looked up in the class return self # looked up on a model instance: return MySequence(instance) def __set__(self, instance, value): # expects a sequence of len(10) # XXX : magic number if len(value) != 10: raise ValueError("yadda yadda") for index, val in enumerate(value): # XXX duplication of MySequence._as_fieldname setattr(instance, "v%s" % (index+1), val) class YourModel(models.Model): # your code here values = MySequenceDescriptor() HTH --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Installing Django 1.0.2...
I am a first time python/django user running "python setup.py install" gives me this error Traceback (most recent call last): File "setup.py", line 69, in version = __import__('django').get_version() File "C:\Django-1.0.2-final\django\__init__.py", line 13, in get_version from django.utils.version import get_svn_revision ImportError: No module named utils.version Any help is appreciated. Thanks for the help. Madhav --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Installing Django 1.0.2...
I am a first time python/django user.. Running "python setup.py install" from django-1.0.2-final directory gives me this error Traceback (most recent call last): File "setup.py", line 69, in version = __import__('django').get_version() File "C:\Django-1.0.2-final\django\__init__.py", line 13, in get_version from django.utils.version import get_svn_revision ImportError: No module named utils.version Any ideas on what I am missing? Thanks Mic --~--~-~--~~~---~--~~ 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: Model fields and arrays?
I too checking for similar thing. Need to store a list of integers/ floats in the model. When we find existing form fields as inadequate, we can define our own fields. What about following the same way here for model fields too? On Dec 31, 9:40 am, schwimwrote: > I'm trying to build a model that will store the counts of each of 10 > possible choices, e.g.: > > v1 = models.IntegerField(default=0) > v2 = models.IntegerField(default=0) > v3 = models.IntegerField(default=0) > ... > v10 = models.IntegerField(default=0) > > I'd prefer to represent this as an array rather than 10 separate > fields. I looked at the CommaSeparatedIntegerField as an alternative, > but I want to explicitly state that there are 10 entries available per > instance. > > Any suggestions on how this can be done, or perhaps a better way to > solve this puzzle? --~--~-~--~~~---~--~~ 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: Getting SQL from QuerySet
On Tue, Dec 30, 2008 at 9:11 PM, Info Cascadewrote: > > Hi -- > > I am getting intermittent errors on certain database queries on our > production server. > I am having a hard time duplicating them (most of the time they run > okay, only sometimes on the production server am I receiving exception > messages), > so I want to log the SQL query itself and see what it is, and why it > might be failing. The Django Debug Toolbar does that and much more http://rob.cogit8.org/blog/2008/Sep/19/introducing-django-debug-toolbar/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---