vDateField and generics views when migrating from oldforms
I have a .97 app that I'm trying to migrate to 1.1. The current hangup is that forms that were generated by generic.create_update were using oldforms under the covers and automatically put the class="vDateField" in place that let the javascript do it's magic and make the calendar selection widget appear. Is there a direct way to get this functionality with generic views derived from "new" forms? Or do I just need to make my own forms by hand that have these attributes set as needed and then pass those to the generic views? 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: data truncation: web page field input vs direct manipulation
Well, somewhere between upgrading to trunk, using smart_unicode and playing around with mysqldb connection settings I'm now getting my data converted. Thanks for your help. On Jul 11, 12:13 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Wed, 2007-07-11 at 05:56 +0000, qhfgva wrote: > > Well, I upgraded to the trunk version of django and now my error looks > > like this: > > > UnicodeDecodeError: 'utf8' codec can't decode byte 0x94 in position 6: > > unexpected code byte > > > Not sure if this is much of an improvement. > [...] > > > > Here's an example with a fancy right quote char: > > > > >>>> p.number = '53 5/8\x94H x 21\x94D x 47 1/4\x94L' > > If you are still using this example, then it's not too surprising you > are seeing this error. Bytestrings (normal Python strings) must use > UTF-8 encoding when passed to Django. Alternatively, you can use Unicode > strings. What you can't do is pass in some arbitrarily encoded sequence > of bytes and hope Django can guess the encoding. It can't do that. > > I can't even guess what byte encoding you are using in the above. I > thought it might be cp-1252, but \x94 is closing double quotes there, > not a right quote (that would be \x92). In any case, it's not UTF-8, so > you are going to have problems. Read the section on string handling in > docs/unicode.txt > (orhttp://www.djangoproject.com/documentation/unicode/#general-string-ha...) > for more details. > > Regards, > Malcolm > > -- > Everything is _not_ based on faith... take my word for > it.http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: data truncation: web page field input vs direct manipulation
Well, I upgraded to the trunk version of django and now my error looks like this: UnicodeDecodeError: 'utf8' codec can't decode byte 0x94 in position 6: unexpected code byte Not sure if this is much of an improvement. On Jul 10, 2:03 am, Horst Gutmann <[EMAIL PROTECTED]> wrote: > qhfgva wrote: > > Every time I think I understand string encoding I get reminded that I > > don't. > > > I have a simple form where I can cut and paste in a value with an > > "interesting" character in it (e.g. "Foo(r)" - in case that doesn't come > > thru that's "F" "o" "o" followed by a registered trademark symbol). > > It gets stored in the database just fine and can then be viewed. If I > > try to manipulate this value directly I get a truncation error. > > > Here's an example with a fancy right quote char: > > >>>> p.number = '53 5/8\x94H x 21\x94D x 47 1/4\x94L' > >>>> p.save() > > Traceback (most recent call last): > > File "", line 1, in ? > > File "c:\Python24\Lib\site-packages\django\db\models\base.py", line > > 218, in save > > db_values + [pk_val]) > > File "c:\Python24\Lib\site-packages\django\db\backends\util.py", > > line 12, in execute > > return self.cursor.execute(sql, params) > > File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 165, > > in execute > > self._warning_check() > > File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 80, in > > _warning_check > > warn(w[-1], self.Warning, 3) > > File "C:\Python24\lib\warnings.py", line 61, in warn > > warn_explicit(message, category, filename, lineno, module, > > registry) > > File "C:\Python24\lib\warnings.py", line 96, in warn_explicit > > raise message > > _mysql_exceptions.Warning: Data truncated for column 'number' at row 1 > > > I can cut an paste the actual string into the web form and it's > > totally happy. I've started to poke around the code to see if I can > > determine what's going wrong, but I was hoping a helpful soul out > > there could point my in the right direction. > > > thanks. > > What version of Django are you using? I also had some truncation errors > thanks to Unicode strings (encoded in ASCII iirc) before, but they > disappeared after the unicode-branch merge :-) > > - Horst --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
data truncation: web page field input vs direct manipulation
Every time I think I understand string encoding I get reminded that I don't. I have a simple form where I can cut and paste in a value with an "interesting" character in it (e.g. "Foo(r)" - in case that doesn't come thru that's "F" "o" "o" followed by a registered trademark symbol). It gets stored in the database just fine and can then be viewed. If I try to manipulate this value directly I get a truncation error. Here's an example with a fancy right quote char: >>> p.number = '53 5/8\x94H x 21\x94D x 47 1/4\x94L' >>> p.save() Traceback (most recent call last): File "", line 1, in ? File "c:\Python24\Lib\site-packages\django\db\models\base.py", line 218, in save db_values + [pk_val]) File "c:\Python24\Lib\site-packages\django\db\backends\util.py", line 12, in execute return self.cursor.execute(sql, params) File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 165, in execute self._warning_check() File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 80, in _warning_check warn(w[-1], self.Warning, 3) File "C:\Python24\lib\warnings.py", line 61, in warn warn_explicit(message, category, filename, lineno, module, registry) File "C:\Python24\lib\warnings.py", line 96, in warn_explicit raise message _mysql_exceptions.Warning: Data truncated for column 'number' at row 1 I can cut an paste the actual string into the web form and it's totally happy. I've started to poke around the code to see if I can determine what's going wrong, but I was hoping a helpful soul out there could point my in the right direction. thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: limit_choices_to: getting access to current instance
Well, either I'm not able to follow your example or we are talking about different things. In any case here is what I got working as a first draft. As a big benefit to me is the fact that I now understand these inner workings a little better. I was hoping to get away with simple wrappers to generic views but now I don't think that will be the case but it also doesn't worry me. :) This is closely adapted from: http://code.pui.ch/2007/01/07/using- djangos-newforms/ from django import newforms as forms from django.newforms import widgets from django.template import loader, Context from django.http import HttpResponse def create_update_animal(request, animal_id=None): animal = None if animal_id: animal = Animal.objects.get(id=animal_id) animal_form = forms.models.form_for_instance(animal) else: animal_form = forms.models.form_for_model(Animal) if animal: available_protocols = Protocol.allowed_for_animal(animal) else: available_protocols = Protocol.active_list() protocol_choices = [('','')] + [(p.id,p.number) for p in available_protocols] animal_form.base_fields['protocol'].widget.choices = protocol_choices if animal: animal_form.base_fields['protocol'].widget.initial = animal.protocol_id if request.method == 'POST': form = animal_form(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect("/") else: form = animal_form() t = loader.get_template('tracker/animal_form.html') c = Context({ 'form': form, }) return HttpResponse(t.render(c)) If there is a way to do the above just using limit_choices_to, I'd still like to understand that method. Also if I'm doing anything particularly hacky feel free to mock me (but also instruct me as to a better way). thanks. On Jan 30, 5:04 pm, "quentinsf" <[EMAIL PROTECTED]> wrote: > Sorry, the reference to 'Display' should have been to 'MyObject' --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: limit_choices_to: getting access to current instance
Thanks for the response. I'm not sure if this exactly covers my case but I like this feature. From the example given in the ticket: def assigned_tasks(): return get_assigned_tasks_id_list(blah, blah) class TimeRecord(models.Model): task = models.ForeignKey(Task, limit_choices_to = {'id__in': assigned_tasks}) I would like the assigned_tasks function to be have a reference to and be able to calculate values based on the current instance of TimeRecord.Perhaps that is what blah or blah are but I'm guessing not. Do I need to do something like work directly with newforms to achieve something like this? On Jan 29, 6:54 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > See patch on ticket <http://code.djangoproject.com/ticket/2445>. > > On Jan 29, 8:31 am, "qhfgva" <[EMAIL PROTECTED]> wrote: > > > If my original post was not entirely clear, I'm interested in any > > method available to limit_choices_to that lets you dynamically create > > the list of available options as a function of the current model > > instance. > > > thanks. > > > On Jan 28, 4:28 pm, "qhfgva" <[EMAIL PROTECTED]> wrote: > > > > I currently have a drop down for a model where I'd only like to show > > > choices that are currently "active". That's easy enough with: > > > > foo = models.ForeignKey(Foo, > > > limit_choices_to={'active__exact':True}) > > > > But if someone is working with a model where the "foo" that they had > > > previously selected has been subsequently set to inactive they should > > > be able to keep that foo (they are "grandfathered" in). > > > > In effect I'd like limit_choices_to to have a list of foo.active == > > > True plus the current selection they have from the past if it is not > > > an active choice. > > > > If I could make a method of Foo such as Foo.allowed_choice_for_x and > > > then pass it an instance of the current object, then it seems like I > > > could easily generate the specific drop downlist on the fly but I'm > > > not sure how to do that (or if it's possible). > > > > Thoughts? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: limit_choices_to: getting access to current instance
If my original post was not entirely clear, I'm interested in any method available to limit_choices_to that lets you dynamically create the list of available options as a function of the current model instance. thanks. On Jan 28, 4:28 pm, "qhfgva" <[EMAIL PROTECTED]> wrote: > I currently have a drop down for a model where I'd only like to show > choices that are currently "active". That's easy enough with: > > foo = models.ForeignKey(Foo, > limit_choices_to={'active__exact':True}) > > But if someone is working with a model where the "foo" that they had > previously selected has been subsequently set to inactive they should > be able to keep that foo (they are "grandfathered" in). > > In effect I'd like limit_choices_to to have a list of foo.active == > True plus the current selection they have from the past if it is not > an active choice. > > If I could make a method of Foo such as Foo.allowed_choice_for_x and > then pass it an instance of the current object, then it seems like I > could easily generate the specific drop downlist on the fly but I'm > not sure how to do that (or if it's possible). > > Thoughts? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
limit_choices_to: getting access to current instance
I currently have a drop down for a model where I'd only like to show choices that are currently "active". That's easy enough with: foo = models.ForeignKey(Foo, limit_choices_to={'active__exact':True}) But if someone is working with a model where the "foo" that they had previously selected has been subsequently set to inactive they should be able to keep that foo (they are "grandfathered" in). In effect I'd like limit_choices_to to have a list of foo.active == True plus the current selection they have from the past if it is not an active choice. If I could make a method of Foo such as Foo.allowed_choice_for_x and then pass it an instance of the current object, then it seems like I could easily generate the specific drop downlist on the fly but I'm not sure how to do that (or if it's possible). Thoughts? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: generic views and non-editable foreign keys
I think you have a small error in your example. Should be: class Thing(models.Model): #element = models.ForeignKey(Thing) element = models.ForeignKey(Element) name = models.CharField(maxlength=100) Also I figured out my problem (I think). I was passing ForeignKey editable=False, apparently this was preventing the POSTed value from being used. So I guess I was misunderstanding the point of editable being False. My hope was to set this value on create and have it be unchangeable after that. How do you even set the value of a column that has editable=False? In otherwords what is this parameter for? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: generic views and non-editable foreign keys
Thanks for the link. Using a wrapper is one of the things I had tried. Here is what I tried. I *think* I'm close, but I don't see the last little bit that I'm missing: models.py class Foo(models.Model): charfoo = models.CharField(maxlength=10) class Goo(models.Model): chargoo = models.CharField(maxlength=10) foo = models.ForeignKey(Foo, editable=False) snippet from urls.py (r'^goo/create/foo_id/(?P\d+)/$', 'myproj.myapp.views.handle_goo_create'), views.py def handle_goo_create(request, foo_id): return django.views.generic.create_update.create_object(request, Goo, post_save_redirect = "/goo/%(id)s/", extra_context = {'foo_id' : foo_id}) goo_form.html {% extends "base.html" %} {% block content %} {% if form.has_errors %} Please correct the following error{{ form.error_dict|pluralize }}: {% endif %} chargoo: {{form.chargoo}} {% if form.chargoo %}*** {{form.chargoo.errors|join:", "}}{% endif %} {% endblock %} When I view this page with the URL: http://localhost:8080/goo/create/foo_id/1/ I see that the foo_id value is populated in the form, but when posted I get: OperationalError at /goo/create/foo_id/1/ (1048, "Column 'foo_id' cannot be null") Request Method: POST Request URL:http://localhost:8080/goo/create/foo_id/1/ Exception Type: OperationalError Exception Value:(1048, "Column 'foo_id' cannot be null") Exception Location: c:\Python23\lib\site-packages\MySQLdb\connections.py in defaulterrorhandler, line 33 Any hints would be greatly appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
generic views and non-editable foreign keys
So far I've been using generic views for everything so I'm not sure if I've reached the end of what those can do, or just need some better understanding of how to use them. I have a Foo model and a Goo model which among other attributes has a non-editable ForeignKey reference back to Foo. I'm having trouble conceptualizing how I should handle getting the foo_id value set automagically in a goo instance at the time it is created. As a guess I was thinking that I could pass an instance of foo_id as part of the extra_context value, but I'm not sure how I could grab this value and put it in place in the urls.urlpatterns: (r'^goo/create/$', 'django.views.generic.create_update.create_object', {'model': Goo, 'post_save_redirect':"/goo/%(id)s/", extra_context: {'foo_id' : ?}}), And if I do figure out how to pass foo_id thru, I'm not sure how this will interact with the template. As a hidden parameter called foo_id or id_foo_id? Any hints on this would be greatly --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
unescaped html in admin column
In order to fit more columns of data on the screen in the admin, I tried the following: # for use in list_display def combined_cols(self): return '%s%s%s' % (self.col1, self.col2,sel.col3) Which displayed the '' in the output. Is there some way to prevent the output from being html escaped in this case? Or is there some other way to format columns in a more condensed form? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
does django go to 11?
I'm in the middle of converting a quixote app over to django. Like many people when I saw the admin app, there was no turning back. I'm trying to leverage the hell out of the admin component and so far the magic genie has granted all my wishes. I'm curious, however, how close I'm getting to the "wall" (there has to be one, no?). 90% of my current functionality is doable via the admin so far. I'd be as happy as a school girl if I can get the other 10% as well for "free" as it were. So here are some general django admin app questions: - Is there a way to have input fields that are only available to certain users/groups? - Is there a way to have certain filters on as default? (Instead of set to "All") - Is there a way to highlight certain rows with colors (e.g. if a row meets a certain condition - e.g. a task past a due date highlighted in red.) - Is there a way to have certain rows not editable based on user/group (e.g the mangager_signoff column is true so non manager users can't modify this row any more)? - Is there a reasonable way to add/remove buttons to/from the save/delete buttons at the bottom of the create/update pages? Thanks in advance. X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.11.53.63 with SMTP id b63mr108828cwa; Sun, 21 May 2006 15:28:35 -0700 (PDT) X-Google-Token: DvftQwwAAAByLOt2cqpwjehr7aYFWCGB Received: from 69.51.79.113 by u72g2000cwu.googlegroups.com with HTTP; Sun, 21 May 2006 22:28:35 + (UTC) From: "qhfgva" <[EMAIL PROTECTED]> To: "Django users" <django-users@googlegroups.com> Subject: does django go to 11? Date: Sun, 21 May 2006 22:28:35 - Message-ID: <[EMAIL PROTECTED]> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/2005 Firefox/1.5,gzip(gfe),gzip(gfe) Mime-Version: 1.0 Content-Type: text/plain I'm in the middle of converting a quixote app over to django. Like many people when I saw the admin app, there was no turning back. I'm trying to leverage the hell out of the admin component and so far the magic genie has granted all my wishes. I'm curious, however, how close I'm getting to the "wall" (there has to be one, no?). 90% of my current functionality is doable via the admin so far. I'd be as happy as a school girl if I can get the other 10% as well for "free" as it were. So here are some general django admin app questions: - Is there a way to have input fields that are only available to certain users/groups? - Is there a way to have certain filters on as default? (Instead of set to "All") - Is there a way to highlight certain rows with colors (e.g. if a row meets a certain condition - e.g. a task past a due date highlighted in red.) - Is there a way to have certain rows not editable based on user/group (e.g the mangager_signoff column is true so non manager users can't modify this row any more)? - Is there a reasonable way to add/remove buttons to/from the save/delete buttons at the bottom of the create/update pages? Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: null=True conditionally
Thanks for your response, I'm not having luck with this. It seems like the admin interface is requiring ForeignKey fields even when marked as null=True. My validator that I wrote seems to be working, but since the fk field is being required it defeats the purpose. Here is my model. Is there anything wrong or am I expecting behavior that doesn't exist? I want it to be the case that - index_number is always required - nih_contract must exist if index_number is of type 'nih' and must be blank otherwise == # -- class IndexNumber(models.Model): contract_type = models.CharField(maxlength=40) name = models.CharField(maxlength=40) def __str__(self): return self.name # -- class NihContract(models.Model): name = models.CharField(maxlength=40) def __str__(self): return self.name # -- def index_number_synched_with_nih_contract(field_data, all_data): try: contract_type = IndexNumber.objects.get(id=(int(all_data['index_number'][0]))).contract_type except: raise validators.ValidationError('IndexNumber had no value!!!') if field_data and contract_type != 'nih' or \ not field_data and contract_type == 'nih': raise validators.ValidationError("All (and only) NIH contracts must have associated NIH contract number.") class LabOrder(models.Model): confirmation_number = models.CharField(maxlength=20, blank=True) catalog_number = models.CharField(maxlength=40, blank=True) request_date= models.DateField(null=True) asap= models.BooleanField() notes = models.CharField(maxlength=255, blank=True) company = models.CharField(maxlength=40, blank=True) product = models.CharField(maxlength=40, blank=True) nih_contract= models.ForeignKey(NihContract, null=True, validator_list=[index_number_synched_with_nih_contract]) cost_estimate = models.FloatField(max_digits=7, decimal_places=2) index_number= models.ForeignKey(IndexNumber) requestor = models.ForeignKey(User) received_date = models.DateField(null=True) received_by = models.CharField(maxlength=40, blank=True) quantity= models.CharField(maxlength=40, blank=True) approved= models.BooleanField(default=False) size= models.CharField(maxlength=40,blank=True) flag= models.BooleanField() --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
null=True conditionally
Class Foo(Model): blah = CharField(maxlength=20) bar = ForeignKey(Qwerty) # requred field baz = CharField(maxlength=20, null=False) In the above class I'd like to make baz a required field if bar is of a certain value otherwise it can be blank. If there a way to accomplish this? Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Limiting selection in admin pages [NEWBIE]
Thanks for the tip. Your example didn't quite work for me. I changed it to: 'groups__name__exact' Possibly it's because we are using different versions? I'm using the most recent trunk (magic-removal-branch). One question if you don't mind answering. I'm guessing that there is juju going on here. name isn't a member of groups, it's a member of just one specific group. I'm assuming that the lookup mechanism is smart enough to check the for the name property in the thing it is chained off of and if that thing is a list then checking for that property in each member of that list. Is the that what's going on here? Thanks again. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---