URL dispatch with name argument throws syntax error
Adding the name argument seems pretty straight forward, but I must be doing something wrong. I am writing tests and have the URLs named seems like the easiest way to look them up. My URL dispatch file was working before I added any of the name='this- name' arguments. Here is my file: from django.conf.urls.defaults import * urlpatterns = patterns('ukca_admin.coupon.mailer_views', (r'^notify/(?P\w+)?/?(?P[\w\-]+)?/?(? P\w+)?/?(?P\w+)?/?$', 'notify_account_manager', name='notify-account-manager'), (r'^build/(?P\d+)?/(?P\w+)?/?(? P[\w\-]+)?/?(?P\w+)?/?(?P\w+)?/?(?P\w+)?/? $', 'mailer_index', name='mailer-index'), (r'^rebuild/offers/(?P\w+)?/?(?P[\w \-]+)?/?(?P\w+)?/?(?P\w+)?/?(?P\w+)?/?$', 'rebuild_offers', name='rebuild-offers'), (r'^rebuild/recipients/(?P\w+)?/?(? P[\w\-]+)?/?(?P\w+)?/?(?P\w+)?/?(?P\w+)?/? $', 'rebuild_recipients', name='rebuild-recipients'), ) And here is the error I get: SyntaxError at /mailer/ ('invalid syntax', ('/var/www/ccadmin/ukca_admin/../ukca_admin/coupon/ mailer_urls.py', 4, 139, " (r'^notify/(?P\\w +)?/?(?P[\\w\\-]+)?/?(?P\\w+)?/?(?P\\w+)?/?$', 'notify_account_manager', name='notify-account-manager'),\n")) Request Method: GET Request URL:http://ccadmin.jt.ccbn.net/mailer/ Exception Type: SyntaxError Exception Value: ('invalid syntax', ('/var/www/ccadmin/ukca_admin/../ukca_admin/coupon/ mailer_urls.py', 4, 139, " (r'^notify/(?P\\w +)?/?(?P[\\w\\-]+)?/?(?P\\w+)?/?(?P\\w+)?/?$', 'notify_account_manager', name='notify-account-manager'),\n")) Exception Location: /usr/lib/python2.6/site-packages/django/utils/ importlib.py in import_module, line 35 Python Executable: /usr/bin/python Python Version: 2.6.4 Python Path:['/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/ usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/ lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/ lib64/python2.6/site-packages', '/usr/lib/python2.6/site-packages', '/ var/www/ccadmin/ukca_admin/../Django-1.1.1', '/var/www/ccadmin/ ukca_admin', '/var/www/ccadmin/ukca_admin/lib', '/var/www/ccadmin/ ukca_admin/../'] Server time:Thu, 22 Apr 2010 16:27:21 +0100 Thanks! --Jim -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: URL dispatch with name argument throws syntax error
Thanks! That was it! I had completely overlooked that and the url() function was even in another URLs file in our project. On Apr 22, 10:45 am, kmtracey wrote: > On Thu, Apr 22, 2010 at 11:34 AM, vjimw wrote: > > Adding the name argument seems pretty straight forward, but I must be > > doing something wrong. I am writing tests and have the URLs named > > seems like the easiest way to look them up. > > > My URL dispatch file was working before I added any of the name='this- > > name' arguments. > > You can't specify name= when you have tuples in your patterns, you must use > the url() function > (http://docs.djangoproject.com/en/dev/topics/http/urls/#url) if you want to > use that syntax. > > 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Unicode Error when Saving Django Model
I have been reading up on Unicode with Python and Django and I think I have my code set to use UTF8 data when saving or updating an object but I get an error on model.save() My database and all of its tables are UTF8 encoded with UTF8 collation (DEFAULT CHARSET=utf8;) The data I am inputting is unicode (u'Save up to 25% on your online order of select HP LaserJet\x92s') But when I try to save this data I get an error Incorrect string value: '\\xC2\\x92s' for column 'title' at row 1 I assume I am missing something, but not sure what I am missing. 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-us...@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: Unicode Error when Saving Django Model
Thanks. It was actually a combination of issues. The database was UTF8, I should have added to my original post that I could manually insert and retrieve UTF8 data. The data we are pulling (migrating one system to a new one, built on django) is a bit of a nest of encoding issues. So things that may look like UTF8 may not be, etc. So I think my attempts to encode this data as UTF8 started the problem. Thanks for the help and the general heads up on encoding and unicode with django. I have read about it, but I understand it better each time I encounter a problem with it. --Jim On May 24, 8:30 am, Karen Tracey wrote: > On Sun, May 23, 2010 at 10:10 PM, vjimw wrote: > > I have been reading up on Unicode with Python and Django and I think I > > have my code set to use UTF8 data when saving or updating an object > > but I get an error on model.save() > > > My database and all of its tables are UTF8 encoded with UTF8 collation > > (DEFAULT CHARSET=utf8;) > > The data I am inputting is unicode > > (u'Save up to 25% on your online order of select HP LaserJet\x92s') > > > > > But when I try to save this data I get an error > > Incorrect string value: '\\xC2\\x92s' for column 'title' at row 1 > > This error implies that your MySQL table is not set up the say you think it > is, with a charset of utf8. Given a table that actually has a utf8 charset: > > k...@lbox:~/software/web/playground$ mysql -p Play2 > Enter password: > Reading table information for completion of table and column names > You can turn off this feature to get a quicker startup with -A > > Welcome to the MySQL monitor. Commands end with ; or \g. > Your MySQL connection id is 5852 > Server version: 5.0.67-0ubuntu6.1 (Ubuntu) > > Type 'help;' or '\h' for help. Type '\c' to clear the buffer. > > mysql> show create table ttt_tag; > +-+ > --- > --+ > | Table | Create > Table > | > +-+ > --- > --+ > | ttt_tag | CREATE TABLE `ttt_tag` ( > `id` int(11) NOT NULL auto_increment, > `name` varchar(88) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 | > +-+ > --- > --+ > 1 row in set (0.00 sec) > > I can create an object in Django using the odd unicode character your > string includes (though I'm not sure what it is supposed to be -- based on > its placement I'd guess it is supposed to be a registered trademark symbol > but that's not what you actually have): > > k...@lbox:~/software/web/playground$ python manage.py shell > Python 2.5.2 (r252:60911, Jan 20 2010, 23:16:55) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > (InteractiveConsole) > > >>> from ttt.models import Tag > >>> t = Tag.objects.create(name=u'HP LaserJet\x92s') > >>> print t > HP LaserJet s > >>> quit() > > So that works, though the character does not print as anything useful. > > If I change the table to have a charset of latin1 (MySQL's default): > > mysql> drop table ttt_tag; > Query OK, 0 rows affected (0.00 sec) > mysql> create table ttt_tag (id int(11) not null auto_increment, name > varchar(88) not null, primary key (id)) engine=myisam default charset > latin1; > Query OK, 0 rows affected (0.01 sec) > > I can then recreate the error you report: > > >>> t = Tag.objects.create(name=u'HP LaserJet\x92s') > > Traceback (most recent call last): > File "", line 1, in > [snipped] > File "/usr/lib/python2.5/warnings.py", line 102, in warn_explicit > raise message > Warning: Incorrect string value: '\xC2\x92s' for column 'name' at row 1 > > So I think one problem is that your table is not actually set up the way you > think it is. > > Another may be that you data is not really correct either. What you are > showing that you have in your data is this character: > > http://www.fileformat.info/info/unicode/char/0092/index.htm > > and I suspect what you really want is either of these: > > http://www.fileformat.info/i
Valid objects are returning an http 404 response
We are having an issue where valid model objects are returning an apache 404 error. Often times, if you hit refresh in the browser a few times, the object is returned with the same URL. We are using Django 1.2.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-us...@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: Valid objects are returning an http 404 response
Actually, we are getting our Django 404 page. Sorry to be unclear on that. The URLs appears as 404 in the access logs. We are actually using fast_cgi per our system administrator and wondered if switching to mod_wsgi might help solve the problem, but it looks like you had the issue with mod_wsgi! Did recompiling apache solve the problem for you with your Django app running mod_wsgi? Thanks for the fast response. Let me know any other information that my be helpful. On Jul 1, 9:00 am, "euan.godd...@googlemail.com" wrote: > When you say "an apache 404 error" do you mean a non-Django styled > one? If so, I think there's something wrong with your apache > configuration and not your Django app. What mechanism are you using to > serve the application? I have seen issues like with this mod_wsgi when > the reload mechanism isn't triggered correctly and you have to restart > apache to get it work correctly. I think in that case it was because > I'd compiled apache slightly incorrectly. I never got to the bottom of > the problem. > > On Jul 1, 2:54 pm, vjimw wrote: > > > > > We are having an issue where valid model objects are returning an > > apache 404 error. Often times, if you hit refresh in the browser a few > > times, the object is returned with the same URL. > > > We are using Django 1.2.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-us...@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: Valid objects are returning an http 404 response
It only happens in our production environment. We have a stage environment, which is a mirror of production, that does not have this behavior and it does not happen on our development or local environments. The trace is a good idea to try to see more information. On Jul 1, 9:28 am, Bill Freeman wrote: > Does it happen when running the development server? If so, you get > a lot more debugging info right up front (access to variables in each > stack from, for instance). If it's still not clear you can use the trace > as a guide as to where to put a pdb.set_trace() (possibly in an if that > makes it only trigger in the interesting circumstance) so that you can > poke around. > > > > On Thu, Jul 1, 2010 at 10:06 AM, vjimw wrote: > > Actually, we are getting our Django 404 page. Sorry to be unclear on > > that. The URLs appears as 404 in the access logs. > > > We are actually using fast_cgi per our system administrator and > > wondered if switching to mod_wsgi might help solve the problem, but it > > looks like you had the issue with mod_wsgi! > > > Did recompiling apache solve the problem for you with your Django app > > running mod_wsgi? > > > Thanks for the fast response. Let me know any other information that > > my be helpful. > > > On Jul 1, 9:00 am, "euan.godd...@googlemail.com" > > wrote: > >> When you say "an apache 404 error" do you mean a non-Django styled > >> one? If so, I think there's something wrong with your apache > >> configuration and not your Django app. What mechanism are you using to > >> serve the application? I have seen issues like with this mod_wsgi when > >> the reload mechanism isn't triggered correctly and you have to restart > >> apache to get it work correctly. I think in that case it was because > >> I'd compiled apache slightly incorrectly. I never got to the bottom of > >> the problem. > > >> On Jul 1, 2:54 pm, vjimw wrote: > > >> > We are having an issue where valid model objects are returning an > >> > apache 404 error. Often times, if you hit refresh in the browser a few > >> > times, the object is returned with the same URL. > > >> > We are using Django 1.2.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-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Valid objects are returning an http 404 response
No, the database is pretty standard (mysql 5.1.37-community). This is an 'in-house' tool and we have about 15 consistent users. They hit is pretty heavily and notice this issue during that time, but it also pops up throughout the day. It does seem to be "fixed," albeit temporarily, after we restart apache, but I am not sure if that is a red-herring since it will pop up again fairly quickly. Before going live we did some basic load testing and did not experience this issue; however, there is a difference between testing and actually using a Web app. On Jul 1, 9:48 am, Tom Evans wrote: > On Thu, Jul 1, 2010 at 3:41 PM, vjimw wrote: > > It only happens in our production environment. We have a stage > > environment, which is a mirror of production, that does not have this > > behavior and it does not happen on our development or local > > environments. The trace is a good idea to try to see more > > information. > > Are you doing anything funky with your databases? Read only slaves? > > Cheers > > Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Valid objects are returning an http 404 response
Sorry to be so slow in responding. We were able to turn debugging on... and no one saw a 404 error with debugging on. Of course, debugging took a toll on the database server so we were not able to just leave it on. We have audited our code and we were able to clean up quite a bit but we do see this problem still, but with less frequency. If we get to the bottom of it, I can post what we did to fix it. On Jul 1, 2:38 pm, Bill Freeman wrote: > I may be just living under a rock, but I don't know how to use > pdb.set_trace() when not using the development server. If you do this > successfully, please let me know. > > What I have done is append "print"ings to a file, or configure extra > logger outputs. Under mod_wsgi I get some logging output in the > apache logs without doing anything special, I don't know how it works > with FCGI. > > Since you say this is an internal tool, you might try DEBUG=True in > settings.py and getting users to come look at their404screens, since > they will then carry extra info. > > > > On Thu, Jul 1, 2010 at 10:41 AM, vjimw wrote: > > It only happens in our production environment. We have a stage > > environment, which is a mirror of production, that does not have this > > behavior and it does not happen on our development or local > > environments. The trace is a good idea to try to see more > > information. > > > On Jul 1, 9:28 am, Bill Freeman wrote: > >> Does it happen when running the development server? If so, you get > >> a lot more debugging info right up front (access to variables in each > >> stack from, for instance). If it's still not clear you can use the trace > >> as a guide as to where to put a pdb.set_trace() (possibly in an if that > >> makes it only trigger in the interesting circumstance) so that you can > >> poke around. > > >> On Thu, Jul 1, 2010 at 10:06 AM, vjimw wrote: > >> > Actually, we are getting our Django404page. Sorry to be unclear on > >> > that. The URLs appears as404in the access logs. > > >> > We are actually using fast_cgi per our system administrator and > >> > wondered if switching to mod_wsgi might help solve the problem, but it > >> > looks like you had the issue with mod_wsgi! > > >> > Did recompiling apache solve the problem for you with your Django app > >> > running mod_wsgi? > > >> > Thanks for the fast response. Let me know any other information that > >> > my be helpful. > > >> > On Jul 1, 9:00 am, "euan.godd...@googlemail.com" > >> > wrote: > >> >> When you say "an apache404error" do you mean a non-Django styled > >> >> one? If so, I think there's something wrong with your apache > >> >> configuration and not your Django app. What mechanism are you using to > >> >> serve the application? I have seen issues like with this mod_wsgi when > >> >> the reload mechanism isn't triggered correctly and you have to restart > >> >> apache to get it work correctly. I think in that case it was because > >> >> I'd compiled apache slightly incorrectly. I never got to the bottom of > >> >> the problem. > > >> >> On Jul 1, 2:54 pm, vjimw wrote: > > >> >> > We are having an issue where valid model objects are returning an > >> >> > apache404error. Often times, if you hit refresh in the browser a few > >> >> > times, the object is returned with the same URL. > > >> >> > We are using Django 1.2.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-us...@googlegroups.com. > >> > To unsubscribe from this group, send email to > >> > django-users+unsubscr...@googlegroups.com. > >> > For more options, visit this group > >> > athttp://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: How can I program multiple drop-down menus at one time by Django?
I think you would want to make a custom widget for the birthday field in your model. http://docs.djangoproject.com/en/dev/ref/forms/widgets/#customizing-widget-instances You can then set up your form instance to use this widget, which would include the three drop downs to make a birthdate selector. On Jul 19, 1:04 am, Boyle Yang wrote: > Hello list, > > I am a new Djangoer. I am trying to program three drop-down menus in > form of Django like the attachment at one > > time . How can I do? > > Thanks very much! > > Boyle Yang > > birthday.bmp > 51KViewDownload -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: stream (large) files from the back-end via Django to the user?
When we upload files to the CDN, we store that path with the object. Then we override the widget for the file so we can server the file directly from the CDN using that field. Would that work for you? On Aug 12, 7:54 am, shi shaozhong wrote: > Dear Markus, > > This is a very interesting topic. > > Please keep me informed of answers. > > Regards. > > David > > On 11 August 2010 15:26, Markus wrote: > > > > > Hi, > > > it was hard to find the right subject. Let me explain what I want to > > do. > > > I write a web application with Django. I have some forms to upload > > content and some forms to download content. Sometimes the content is > > just a string (than it will be stored in a database) but sometimes the > > content is a (large) file. Than the file will be stored to a > > distributed file system running in the background. > > > Uploading the files is not a problems. First Django stores the file to > > a local directory of the server and than it get moved to the > > distributed file system. Not really nifty but I couldn't find a > > solution to stream the data directly to the distributed file system. > > > But the really hard part is the download. How do I serve this files > > back to the user? Sure, I could do the same as I do for upload: First > > download the files from the distributed file system to the local file > > system and than serve it to the users. But when has the user finished > > the download and I can remove the local copy of the file? Just to > > mention one open question. > > > I hope I could describe my problem in an understandable way. > > > What would be a good way to serve internal files to a user? Is it > > possible to pipe the files directly from the distributed file system > > to the user? > > > Cheers, > > Markus > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Save_model versus model.save() and the order they are called.
We have a model object (Offer) which has a number of business rules. 1) On create, auto populate the created_by field with the request.user data 2) On modify, auto populate the last_edited_by field with the request.user data 3) If a date value change on modify, audit with the object, date and last_edited_by user The created_by and last_modified_by values are being populated automatically in save_model() in the admin for Offer using class OfferAdmin(admin.ModelAdmin) def save_model(self, request, obj, form, change): # If add, set created_by... # For both add and change, update last_edited_by obj.last_edited_by_id = request.user # A few other code updates obj.save() This works just fine! The next set of business rules are based around a date changing when an edit form is submitted. If the date entered by the user changes, and matches some rules, we want to audit this and tag it with the last_edited_by user for that current form submit. For this we are overriding the save() method for the model object class Offer(models.Model). To keep track of the original object data (versus the form submitted data) I am using the __init__ method on the model like this: def __init__(self, *args, **kwargs): super(Offer, self).__init__(*args, **kwargs) self.__original_end_date = self.end_date self.__original_last_edited_by = self.last_edited_by For the date, which is always manipulated through the form, this works like a charm. We can compare self.end_date with self.__original_end_date and see if the data has changed. For the last_edited_by field, which is not updated in the form but is set in save_model() we actually get the original value and not the value set in save_model(). Any idea how I can get my new auto populated data here instead of the original value? I looked at the Django admin code and see that save_model() just calls obj.save() so I am not sure why I don't see my set data from save_model() but the original value for the last_edited_by field. I also noticed that my model save() override method is called twice. The first time with the original date and the new date, but with last_edited_by ONLY being the original value and then AGAIN with the dates both set to the new date but with the original last_edited_by and new last_edited_by... so I get the change but I just don't get both changes in the same save() call which means I cannot test for both conditions. At the end of the day, the correct user for the last_edited_by field ends up in the admin tool and database, but the order in which items are called is throwing me. 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-us...@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: Overriding ModelForm field's value in the admin changeview
The form and object are combined when you call: response = super([YOURMODELFORMHERE], self).change_view(request, object_id, extra_context=my_context) You can see what the admin code for def change_view does in Django1.*/ django/contrib/admin/options.py I was looking at the same thing and found an alternate route to for my needs since I didn't need the value to be updated before the form was rendered. On Jul 14, 1:03 pm, Chuck Harmston wrote: > Does anyone know where in the admin changeview the fields in a ModelForm is > populated with the information from the database? I was hoping to override > one of the fields in a subclassed ModelForm.__init__(), e.g.: > > self.base_fields[field_name].initial = 'foo' > > But the population appears to be happening farther down the chain, as 'foo' > is overwritten with the value from the database. > > 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-us...@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: Save_model versus model.save() and the order they are called.
I remedied this problem by actually doing all of my work in the save_model() method. It has all the initial data set on the model which allowed me to check which values changed (date and/or user) and set audits as needed. On Aug 12, 4:06 pm, vjimw wrote: > We have a model object (Offer) which has a number of business rules. > 1) On create, auto populate the created_by field with the request.userdata > 2) On modify, auto populate the last_edited_by field with the > request.userdata > 3) If a date value change on modify, audit with the object, date and > last_edited_by user > > The created_by and last_modified_by values are being populated > automatically in save_model() in the admin for Offer using class > OfferAdmin(admin.ModelAdmin) > > def save_model(self, request, obj,form, change): > # If add, set created_by... > # For both add and change, update last_edited_by > obj.last_edited_by_id = request.user > # A few other code updates > obj.save() > > This works just fine! > > The next set of business rules are based around a date changing when > an editformis submitted. If the date entered by the user changes, > and matches some rules, we want to audit this and tag it with the > last_edited_by user for that currentformsubmit. For this we are > overriding thesave() method for the model object class > Offer(models.Model). > > To keep track of the original objectdata(versus theformsubmitteddata) I am > using the __init__ method on the model like this: > > def __init__(self, *args, **kwargs): > super(Offer, self).__init__(*args, **kwargs) > self.__original_end_date = self.end_date > self.__original_last_edited_by = self.last_edited_by > > For the date, which is always manipulated through theform, this works > like a charm. We can compare self.end_date with > self.__original_end_date and see if thedatahas changed. For the > last_edited_by field, which is not updated in theformbut is set in > save_model() we actually get the original value and not the value set > in save_model(). > > Any idea how I can get my new auto populateddatahere instead of the > original value? > > I looked at the Django admin code and see that save_model() just calls > obj.save() so I am not sure why I don't see my setdatafrom > save_model() but the original value for the last_edited_by field. I > also noticed that my modelsave() override method is called twice. The > first time with the original date and the new date, but with > last_edited_by ONLY being the original value and then AGAIN with the > dates both set to the new date but with the original last_edited_by > and new last_edited_by... so I get the change but I just don't get > both changes in the samesave() call which means I cannot test for > both conditions. > > At the end of the day, the correct user for the last_edited_by field > ends up in the admin tool and database, but the order in which items > are called is throwing me. > > 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-us...@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.
Admin Inlines only show up after a browser refresh
We have an odd situation where, for one of our model forms, the inlines do not regularly show up on the form page, but if you refresh the browser window, they will appear with the correct data. Has anyone else run into this before? I am not really sure how to debug it since it is not consistent. However, i do know that it is not tied to a specific browser (I can make it happen in Safari, Chrome or Firefox) and sometimes they do show up. When I have django toolbar debug turned on in my development environment it does not show any indication of the inlines when they don't show up so it tells me something is happening further upstream. Here is the admin code to build the ModelAdmin form in this instance: class LegalObjectActionInline(admin.TabularInline): model = LegalObjectAction class LegalObjectAdmin(admin.ModelAdmin): save_on_top = True form = LegalObjectForm list_display = ( 'offer_code', 'legal_site', 'created_by', 'copyright_or_trademark', 'store', 'current_state', 'overdue' ) list_filter = ( 'created', 'modified', 'copyright_or_trademark', 'legal_site',) list_select_related = True search_fields = ['legal_site', 'store', 'copyright_or_trademark'] fields = ('offer_code', 'store', 'copyright_or_trademark', 'page_found', 'legal_site', ) inlines = [LegalObjectActionInline,] 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-us...@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: Alphabetic filtering of Django Admin drop down menu
Should your relationship be Many-to-Many I found this to be very helpful: Autocomplete manytomany widget for admin panel http://djangosnippets.org/snippets/1365/ On Dec 7, 1:29 pm, Heigler wrote: > If you can't use raw_id_fields i guess you should write that view and > use javascript to search inside the view. > > Can you use a auto complete approach instead a drop down menu? If you > can, my suggestion is to use a jquery plugin to do the hard > work:http://docs.jquery.com/Plugins/autocomplete -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.