displaying a foreign key in admin list and template exception
Hi all, I'm having some problems and I've isolated them in a small example. I have the following data model: class Currency(meta.Model): name = meta.CharField(maxlength=5) def __repr__(self): return self.name class META: admin = meta.Admin() class CustomData(meta.Model): amount = meta.IntegerField() loan = meta.IntegerField() currency = meta.ForeignKey(Currency, to_field='name') def __repr__(self): return self.amount class META: admin = meta.Admin( list_display = ('amount', 'loan', 'currency'), ) Now, addinga a currency works fine. Trying to add a customdata, when saving, yelds a template exception. I've read on this group that this might be because something's wrong in the model. Any ideas? The other problem is that with the current list_display in CustomData, there is no listing of the items. Just "3 custom datas". Once I remove 'currency' from list_display, I get them listed ok. This is driving me mad. I'm probably doing something wrong, but I can't figure out what. Thanks, Andu
Re: Bug in MultiValueDict?
On 2/10/06, Andrew Degtiariov <[EMAIL PROTECTED]> wrote: > def complete(self, request, data): > debug('complete: %s' %repr(data)) > debug('complete: %s' %repr(data['costs']) > . > > First debug() call produced: > complete: ['\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82x'], 'unit_type': ['B'], > 'costs': ['1', '2', '3'], 'frequency': ['D'], 'license_fee': [15.0], > 'setup_fee': [185.0], 'description': > ['\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd1\x8b\xd0\xb9 > \xd1\x81\xd0\xb5\xd1\x80\xd0\xb2\xd0\xb8\xd1\x81 ']}> > > Please note that the value stored with a 'costs' key is list. > > Second debug() call produced: > complete: '3' > > There is regular string - last value from 'costs'. Don't know is it fixed > or not, if yes, could you give me patch or solution for Django 0.91 > how I can obtain list instead of string? Hi Andrew, This isn't a bug -- it's intended behavior. When you access an element in a MultiValueDict, it returns the last item, as a string. See the docs for more info: http://www.djangoproject.com/documentation/request_response/#querydict-objects If you want to get a list instead of a string, use data.getlist('costs') instead of data['costs']. Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org --~--~-~--~~~---~--~~ 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: iterator lookup function crashs
Hi Adrian, You're right. Shame on me ! Thanks a lot. Seb --~--~-~--~~~---~--~~ 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: locale settings
On 2/8/06, TT <[EMAIL PROTECTED]> wrote: > I found an interesting way to handle locales in admin's date_hierarchy > feature. When day_lookup (GET-parameter 'variable'__day) is part of the > request, the response uses django.utils.dates.MONTH in month's name, > which uses gettext to translate month names, but other requests uses > Python's strftime -function. This forces me to use Python's > locale.setlocale in settings, so I can get month names in my own > language. Is there some good reason to not use Python's locale module > in Django or why this is not used in Django as default? I'm not sure I understand the problem -- could you give a bit more explanation, possibly with an example? Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org --~--~-~--~~~---~--~~ 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: iterator lookup function crashs
On 2/10/06, Sebastien Fievet <[EMAIL PROTECTED]> wrote: > TypeError: got unexpected keyword argument 'event__exact' > > What's wrong with my code ? (I've got the last SVN version of Django, > v2299) Hey Sebastien, You need to use event__id__exact, not event__exact. Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org --~--~-~--~~~---~--~~ 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: admin interface can't find table
Sorry for the spam all, I should've check the bug tracker (#930) first... James S. Martin, RHCE Contractor Administrative Office of the United States Courts Washington, DC (202) 502-2394 --~--~-~--~~~---~--~~ 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: iterator lookup function crashs
Oups, you should read : >>> from django.models.flood import members, events >>> e = events.get_values(pk=1) >>> for m in members.get_iterator(event__exact=e): ... print m --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
iterator lookup function crashs
Hi all, i'm trying to use the iterator lookup function on my model, but it failed. My model is the following : from django.core import meta STATUS_CHOICES = ( (0, 'Added'), (1, 'Requested'), (2, 'Registered'), ) # Create your models here. class User(meta.Model): msisdn = meta.CharField(maxlength=12, db_index=True, unique=True) first_name = meta.CharField(maxlength=30) last_name = meta.CharField(maxlength=30) class META: admin = meta.Admin() def __repr__(self): return "%s %s" % (self.first_name, self.last_name) def _pre_save(self): self.first_name = self.first_name.capitalize() self.last_name = self.last_name.capitalize() self.msisdn = self.msisdn.replace(' ', '') self.msisdn = self.msisdn.replace('.', '') class User_Extended(meta.Model): user = meta.ForeignKey(User) user_agent = meta.CharField(maxlength=255, core=True) class META: admin = meta.Admin() verbose_name_plural = 'users_extended' module_name = 'users_extended' class Event(meta.Model): name = meta.SlugField() repr_date = meta.DateTimeField(verbose_name="representation date") class META: admin = meta.Admin() def __repr__(self): return self.name class Member(meta.Model): user = meta.ForeignKey(User) event = meta.ForeignKey(Event) status = meta.IntegerField(choices=STATUS_CHOICES) class META: admin = meta.Admin() def __repr__(self): return "%r (%r)" % (self.get_user(), self.get_event()) And i try to do the following : >>> from django.models.flood import members >>> e = events.get_values(pk=1) >>> for m in members.get_iterator(event__exact=e): ... print m The following error is raised : Traceback (most recent call last): File "", line 1, in ? File "/home/sfievet/public_html/django_src/django/core/meta/__init__.py", line 1377, in function_get_iterator select, sql, params = function_get_sql_clause(opts, **kwargs) File "/home/sfievet/public_html/django_src/django/core/meta/__init__.py", line 1601, in function_get_sql_clause tables2, join_where2, where2, params2, _ = _parse_lookup(kwargs.items(), opts) File "/home/sfievet/public_html/django_src/django/core/meta/__init__.py", line 1512, in _parse_lookup _throw_bad_kwarg_error(kwarg) File "/home/sfievet/public_html/django_src/django/core/meta/__init__.py", line 1455, in _throw_bad_kwarg_error raise TypeError, "got unexpected keyword argument '%s'" % kwarg TypeError: got unexpected keyword argument 'event__exact' >>> What's wrong with my code ? (I've got the last SVN version of Django, v2299) Many 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: tiny patch to improve the url validating regex
On 2/9/06, EricHsu <[EMAIL PROTECTED]> wrote: > when I tried to save an "https://...; url into the db, the django's > manipulator kept complaining that it was invalid. It is because the > django/core/validators.py's url_re is a little bit too simple, the > url_re pattern accepts only url begins with "http://;. Hey Eric, Thanks for the pointer on this. I've updated the code in trunk to accept "https". Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org --~--~-~--~~~---~--~~ 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: auto-login upon registration
On 2/10/06, Jeremy Jones <[EMAIL PROTECTED]> wrote: > I have the following view which adds users to the User table (and > SimpleUserManipulator is a class I've defined). Is there a way I can > automatically login the user once the record is saved? Hey Jeremy, Sure, just do this, after you've created the User object (u): request.session[users.SESSION_KEY] = u.id I've added a section to the docs: http://www.djangoproject.com/documentation/authentication/#how-to-log-a-user-in Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org --~--~-~--~~~---~--~~ 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: admin interface can't find table
django-users@googlegroups.com wrote on 02/09/2006 07:20:35 PM: > So this is a strange problem...I'm getting the Following error when try to > view the list mode of my court_detals object in the Admin interface. > snip. To be a little less verbose, I think the SQL handler in django is not handling my One to One relationship correctly. SELECT `contrack_court_details`.`sector`,`contrack_court_details`.`type`,`contrack_court_details`.`district`,`contrack_court_details`.`court_id` FROM `contrack_court_details` ORDER BY `contrack_locations`.`id` DESC It _should_ be this (I constructed this by hand and it works): SELECT `contrack_court_details`.`sector`,`contrack_locations`.`id`,`contrack_court_details`.`type`,`contrack_court_details`.`district`,`contrack_court_details`.`court_id` FROM `contrack_court_details`, `contrack_locations` ORDER BY `contrack_locations`.`id` DESC So django is leaving out the table to which OneToOneField is tied to... Please tell me I'm doing something wrong and it's not a bug. :) James S. Martin, RHCE Contractor Administrative Office of the United States Courts Washington, DC (202) 502-2394 --~--~-~--~~~---~--~~ 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: memcached + multiple virtual hosts
On Feb 10, 2006, at 1:57 AM, Roberto Aguilar wrote: > I'm planning on running multiple websites on one server using virtual > hosts. I also want to run memcached and wanted to know what the best > way to avoid "name collisions". The best way to do it is to make sure that your keys have identifier unique to the given site in them. I always prefix my keys with settings.SITE_ID; you may want to do that same. Jacob --~--~-~--~~~---~--~~ 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: Template engine error?
On 2/10/06, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > > On Friday 10 Feb 2006 2:38 pm, Tobias wrote: > > TemplateSyntaxError: Caught an exception while rendering. > > usualy templatesyntaxerror has nothing to do with templates - there > may be a syntax error in your model itself - a missing comma or a > borked __repr__. Did you run 'validate'? > many times what I do is modify the template code and write: except: import traceback traceback.print_exc() raise ... Because template module swallows the real exception information, only raise it's own exception. So I suggest that may be the error infomation can be shown more? -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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: Recursive self referring foreignkeys
Thanks! Thats just what I needed! --~--~-~--~~~---~--~~ 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: Template engine error?
On Friday 10 Feb 2006 2:38 pm, Tobias wrote: > TemplateSyntaxError: Caught an exception while rendering. usualy templatesyntaxerror has nothing to do with templates - there may be a syntax error in your model itself - a missing comma or a borked __repr__. Did you run 'validate'? -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ வாழ்க! --~--~-~--~~~---~--~~ 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: Recursive self referring foreignkeys
Rudolph wrote: > With meta.ForeignKey("self") you can create an object that can refer to > objects from the same type. But how do I prevent loops? (like an object > that refers to itself, or object A refers to object B which refers back > to object A). With limit_choices_to I could prevent an object from > selecting itself, but how do I prevent bigger loops? The easiest way to iterate through and find a loop during the save() call of the object. (Using _pre_save() for pre-magic-removal code.) An example is provided in this cookbook entry: http://code.djangoproject.com/wiki/CookBookCategoryDataModel - --Max Battcher-- http://www.worldmaker.net/ --~--~-~--~~~---~--~~ 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: Django and PCMEF vs MVC
On 2/10/06, Max Battcher <[EMAIL PROTECTED]> wrote: > > A few thoughts on architecture: > http://blog.worldmaker.net/node/211 > > I had architecture thoughts in my head from class and felt I could apply > them somewhat to Django. I'm not sure if its useful or interesting, but > hopefully somebody might find use of it or interest in it. > good! I don't hear about PCMEF before. -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django and PCMEF vs MVC
A few thoughts on architecture: http://blog.worldmaker.net/node/211 I had architecture thoughts in my head from class and felt I could apply them somewhat to Django. I'm not sure if its useful or interesting, but hopefully somebody might find use of it or interest in it. -- --Max Battcher-- http://www.worldmaker.net/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Template engine error?
Hi, everyone, trying to get my first Drango project running, I got the following error for an "add" action: Traceback (most recent call last): File "...\django\core\servers\basehttp.py", line 272, in run self.result = application(self.environ, self.start_response) File "...\django\core\servers\basehttp.py", line 615, in __call__ return self.application(environ, start_response) File "...\django\core\handlers\wsgi.py", line 155, in __call__ response = self.get_response(request.path, request) File "...\django\core\handlers\base.py", line 109, in get_response return self.get_technical_error_response(request) File "...\django\core\handlers\base.py", line 139, in get_technical_error_response return debug.technical_500_response(request, *sys.exc_info()) File "...\django\views\debug.py", line 126, in technical_500_response return HttpResponseServerError(t.render(c), mimetype='text/html') File "...\django\core\template\__init__.py", line 146, in render return self.nodelist.render(context) File "...\django\core\template\__init__.py", line 707, in render bits.append(self.render_node(node, context)) File "...\django\core\template\__init__.py", line 725, in render_node result = node.render(context) File "...\django\core\template\defaulttags.py", line 112, in render nodelist.append(node.render(context)) File "...\django\core\template\defaulttags.py", line 179, in render return self.nodelist_true.render(context) File "...\django\core\template\__init__.py", line 707, in render bits.append(self.render_node(node, context)) File "...\django\core\template\__init__.py", line 735, in render_node raise wrapped TemplateSyntaxError: Caught an exception while rendering. ([path to python]\lib\site-packages\django-0.91-py2.4.egg replaced by ...) I didn't do anything fancy to the templates -- just the minimal changes which are part of the tutorial (I zipped my application template directory, if anyone wants to have a look him/herself). Any ideas what to do? TIA, Tobias --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
is_member_of method for user objects
Hello, I wasn't able to find an easy way to check if a user is a member of a group, so I added the method; here is a patch for: django/django/models/auth.py Index: auth.py === --- auth.py (revision 2296) +++ auth.py (working copy) @@ -142,6 +142,12 @@ self._perm_cache.update(self.get_group_permissions()) return self._perm_cache +def is_member_of(self, group_name): +for group in self.get_group_list(): +if group.name == group_name: +return True +return False + def has_perm(self, perm): "Returns True if the user has the specified permission." if not self.is_active: Hers is some quick usage: from django.models.auth import users u = users.get_object(pk=1) if u.is_member_of('super_group'): print 'yay!' Would it be possible for me to use this function within a template, for example: {% if user.is_member_of:"blah" %} The above, of course, does not work. Thanks! -berto. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---