Re: update_object generic view doesn't see model's get_absolute_url
Solved. I used Django's traces to discover that the object wasn't being passed to the view on POST. Inserting some exceptions in different places in the source, I found that it was at the point the form was saved that the model reference was lost. Looking at the form I realized I wasn't returning the object after saving it in the save method. It figures that as soon as I decide to give up and ask the question I find the answer 5 minutes later. -- 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: UnicodeEncodeError
Daniel, if I don't do that, I get the unicode error in the list of dashboards in the admin section. On Fri, Jul 30, 2010 at 04:29, Daniel Rosemanwrote: > On Jul 29, 11:27 pm, Eric wrote: > > I am getting this error in the Django Administration section when I > > add an entry for a Dashboard object. > > > > When I return to the item in the Admin section, the record has been > > added and it displays correctly in the list of Dashboard objects. When > > I click on it, it shows correctly. Only when I add a new one or save > > one does that happend. And, I noticed that the history is not > > populated. > > > > The traceback is: > > > > Environment: > > > > Request Method: POST > > Request URL:http://127.0.0.1:8000/admin/dashboard/dashboard/1/ > > Django Version: 1.2.1 > > Python Version: 2.6.2 > > Installed Applications: > > ['django.contrib.auth', > > 'django.contrib.contenttypes', > > 'django.contrib.sessions', > > 'django.contrib.sites', > > 'django.contrib.messages', > > 'django.contrib.admin', > > 'ManagementReview.dashboard'] > > Installed Middleware: > > ('django.middleware.common.CommonMiddleware', > > 'django.contrib.sessions.middleware.SessionMiddleware', > > 'django.middleware.csrf.CsrfViewMiddleware', > > 'django.contrib.auth.middleware.AuthenticationMiddleware', > > 'django.contrib.messages.middleware.MessageMiddleware') > > > > Traceback: > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/core/handlers/base.py" in get_response > > 100. response = callback(request, > > *callback_args, **callback_kwargs) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/contrib/admin/options.py" in wrapper > > 239. return self.admin_site.admin_view(view)(*args, > > **kwargs) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/utils/decorators.py" in _wrapped_view > > 76. response = view_func(request, *args, > > **kwargs) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/views/decorators/cache.py" in > > _wrapped_view_func > > 69. response = view_func(request, *args, **kwargs) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/contrib/admin/sites.py" in inner > > 190. return view(request, *args, **kwargs) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/utils/decorators.py" in _wrapper > > 21. return decorator(bound_func)(*args, **kwargs) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/utils/decorators.py" in _wrapped_view > > 76. response = view_func(request, *args, > > **kwargs) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/utils/decorators.py" in bound_func > > 17. return func(self, *args2, **kwargs2) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/db/transaction.py" in > > _commit_on_success > > 299. res = func(*args, **kw) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/contrib/admin/options.py" in > > change_view > > 901. self.log_change(request, new_object, > > change_message) > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/contrib/admin/options.py" in log_change > > 443. object_repr = force_unicode(object), > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/site-packages/django/utils/encoding.py" in force_unicode > > 66. s = unicode(s) > > File "/Users/Eric/Documents/DjangoProjects/ManagementReview/../ > > ManagementReview/dashboard/models.py" in __unicode__ > > 47. return u"%s" % self.name.decode('utf-8') > > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/encodings/utf_8.py" in decode > > 16. return codecs.utf_8_decode(input, errors, True) > > > > Exception Type: UnicodeEncodeError at /admin/dashboard/dashboard/1/ > > Exception Value: ('ascii', u"Eric's Nifty D\xe4shboard Entry", 14, 15, > > 'ordinal not in range(128)') > > > > The model looks like this: > > > > class Dashboard(models.Model): > > name = models.CharField("Dashboard name",max_length=100) > > fiscal_year = models.IntegerField("Fiscal year") > > region = models.CharField("Region", max_length=30) > > review_date = models.DateField("Review date") > > date_completed = models.DateField("Date Completed") > > > >
update_object generic view doesn't see model's get_absolute_url
I am using the generic view django.views.generic.create_update.update_object to edit a model. The form is displayed, the model gets updated, but on redirect, I get an ImproperlyConfigured exception. Django tells me I need to define a get_absolute_url method, but I already did, it just doesn't seem to be seeing it. What's going on here? -- 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: manage.py hangs near (or at) the end
fwiw, the user error in question was that a developer had added a call to threading outside of any function definition or protected area. as such the manage.py process finished, but the thread was left hanging. On Jul 21, 6:16 pm, "psgou...@gmail.com"wrote: > I've seen a few references to something like this happening, but > nothing quite right. > > somewhere along the line, I have become unable to run manage.py and > have it exit cleanly. it will appear to do everything that it is > supposed to do. (with exceptions,) and then hang. > > for example, > in mysql, create the database needed, > in the app folder, execute 'python manage.py syncdb --noinput -v 2' > > according to the verbose output, all the tables are created, there is > a section looking for fixtures, ending with the line: > No fixtures found. > > which would seem to indicate that it's getting through almost > everything and dying right at the end of it all. > > however, it will not return. and I am forced to kill the python > process manually. after restarting apache, the app will operate as > expected, indicating (it would seem) that the problem is largely > cosmetic. > > now, at one point this was working. and the command output ended with > the same line, but it would return. > > nothing obvious in the actual app code seems like it would cause this > problem. can anyone suggest anything likely? when syncdb executes is > there anything known that would trip it up based on the contents of > the app being synced? > > cheers -- 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: Flexigrid
El 30/07/10 15:41, Ramesh escribió: > I want to use Flexigrid for my project. I have used it before on > TurboGears and it's really nice. > > Can somebody please help me how can I use flexigrid for my project? > tutorials link to start for using Flexigrid on django? > http://is.gd/dTrPN -- Gonzalo Delgado-- 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.
*Unnecessary* instances of HTML escape sequences like ?
I understand the need for web pages to denote the 5 HTML special characters >, &, <, ', and " with alternate representations like . (These 5 are the *only* special characters in HTML right?) What I don't understand is why an HTML page encoded with UTF-8 would use this
Flexigrid
Hi, I want to use Flexigrid for my project. I have used it before on TurboGears and it's really nice. Can somebody please help me how can I use flexigrid for my project? tutorials link to start for using Flexigrid on django? Thanks a lot in advance, RB -- 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.
how to get parent of related m2m model instance from within a template?
I have a model, which has a related model, which then has a related m2m field (See defs below). I want to add a method to the m2m model (ie: "Button") which, when called in a template, will get me the original record that called the relation. Is this possible? See method attempt below in the "Button" model, called "get_duid". The point in this attempt is to be able to return the original id within the template when iterating through the buttons of a particular "DocumentUnit". class DocumentUnit(models.Model): parent = models.ForeignKey('self', null=True, blank=True, related_name='children') unittype= models.ForeignKey(DocumentUnitType, related_name='du') content = models.TextField() class DocumentUnitType(models.Model): name= models.CharField(max_length=40) description = models.CharField(max_length=255, blank=True) buttons = models.ManyToManyField('Button', null=True, blank=True, related_name='button_du_types') class Button(models.Model): btn_code= models.CharField(max_length=20) title = models.CharField(max_length=50, blank=True) href= models.CharField(max_length=150, blank=True) viewname= models.CharField(max_length=50, blank=True) css_class = models.CharField(max_length=70, blank=True) text= models.CharField(max_length=50, blank=True) prefix_id = models.CharField(max_length=20) order = models.IntegerField(blank=True, null=True) def get_duid(self): return self.button_du_types.pk Thanks for any help you can give me with this. -- 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: django_session not in "default" DB
Hi, Thanks for your previous reply. I'm still having problems... now I'm getting the following error: NameError: global name 'Session' is not defined I check up the documentation, I understand that 'django.contrib.sessions.backends.db' makes the Session model available in the DB router so, just by setting the 'django.contrib.session' in my INSTALLED_APPS is enough ? What am I missing ? Thanks again. On Jul 29, 3:39 pm, Dennis Kaarsemakerwrote: > On do, 2010-07-29 at 13:03 -0700, Jocelo wrote: > > > Hi, > > > I have two DB configured on my django project... one in oracle and the > > other one in MySQL... > > My Oracle DB is the default one, and on MySQL I store data that is not > > really related to my main application. > > > I want to store session data in MySQL, since oracle is legacy but > > whenever I try to store something on my session object > > ("request.session['temp']=1"), django looks for django_session table > > on Oracle, crashing completely my app. > > > I have read something about dabatase routing, but I'm not sure if this > > is the way to go for this. > > It is the way to go. > > > How can I make django look for django_session's table on my > > "secondary" MySQL DB ? > > http://docs.djangoproject.com/en/dev/topics/db/multi-db/#automatic-da...has > all the details. your router would look like: > > class MyRouter(object): > def db_for_read(model, **hints): > if model == Session: > return 'secondary' > db_for_write = db_for_read > > -- > Dennis K. > > They've gone to plaid! -- 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: field.label in template converts to lower case in 1.2.1
Thanks Jason! That fixed the issue. On Fri, Jul 30, 2010 at 10:23 AM, Jasonwrote: > Actually - make that change to the rest of the field options too. The > word wrap threw me off there at the end. > > On Jul 30, 8:16 am, Jason wrote: > > Looks like you are generating the fields in two different cases. > > Here's the second one: > > > > self.fields[config.ConfigurationName] = > > forms.ChoiceField( > > choices=choicelist, > > required=False) > > > > Change that to: > > > > self.fields[config.ConfigurationName] = > > forms.ChoiceField( > > label = > > config.ConfigurationName, > > choices=choicelist, > > required=False) > > > > (and make the same change to the multiple select as well) > > > > Assuming the ConfigurationName has proper capitalization it should > > work. > > > > On Jul 30, 5:26 am, Jeff Green wrote: > > > > > Here is my form class > > > > > class StationInfo( forms.Form): > > > > > def __init__( self, *args, **kwargs): > > > super( StationInfo, self).__init__( *args, **kwargs) > > > > > request = args[1] > > > selecttuple = "choice0", "--Select One--" > > > > > userid = threadlocals.get_current_user() > > > user = '%s' % userid > > > userrec = User.objects.get(username=user) > > > projrecs = UserProj.objects.filter( User=userrec) > > > self.projlist = [] > > > phaselist = [] > > > for proj in projrecs: > > > self.projlist.append( proj.ProjectId) > > > > > # Get all the configurations for a station > > > stationrec = request.session['stationrec'] > > > configlist1 = Configuration.objects.filter( > > > ConfigurationType='Station', AdditionalEquipFlag=False) > > > configlist2 = Configuration.objects.filter( > > > ConfigurationType='Station', > > > > AdditionalEquipFlag=True).order_by('ConfigurationName') > > > configlist = list(chain(configlist1, configlist2)) > > > > > for config in configlist: > > > config_str = '%s' % config > > > foundconfig = True > > > # Get station configuration record for given station > > > configstr_list = [] > > > try: > > > stationconfiglist = StationConfig.objects.filter( > > > > > > ConfigValueId__ConfigurationId__ConfigurationName=config.ConfigurationName, > > > EndDate__isnull=True, > > > StationId=stationrec > > > ) > > > if len(stationconfiglist) == 0: > > > foundconfig = False > > > else: > > > for stationconfigrec in stationconfiglist: > > > configstr = '%s' % > stationconfigrec.ConfigValueId > > > configstr_list.append( configstr) > > > > > except: > > > foundconfig = False > > > > > # Get choice list > > > choicelist = [] > > > if config_str == 'Phase' or config_str == 'Project': > > > configvalues = ConfigValues.objects.filter( > > > > > ConfigurationId__ConfigurationName=config.ConfigurationName > > > ).order_by( 'ConfigValue') > > > else: > > > configvalues = ConfigValues.objects.filter( > > > > > ConfigurationId__ConfigurationName=config.ConfigurationName, > > > ProjectId__in = self.projlist).order_by( > 'ConfigValue') > > > if not foundconfig: > > > if config.MultiSelectFlag: > > > choicelist.append( selectmoretuple) > > > else: > > > choicelist.append( selecttuple) > > > select_fieldlist = [] > > > allchoiceslist = [] > > > for configrec in configvalues: > > > configvalstr = '%s' % configrec > > > allchoiceslist.append( configvalstr) > > > choicestr = "choice%s" % str( configrec.id) > > > choicetuple = choicestr, configrec.ConfigValue > > > if configrec.ConfigValue in configstr_list: > > > choicelist.insert( 0, choicetuple) > > > select_fieldlist.append( choicestr) > > > else: > > > choicelist.append( choicetuple) > > > > > for stationconfigrec in stationconfiglist: > > > configstr = str( stationconfigrec.ConfigValueId) > > > # Tried if not in list but it gave incorrect result > > > found = False > > > for choice in allchoiceslist: > > > if configstr ==
Re: Form Validation
On Jul 30, 4:49 pm, rupertwrote: > Here's the view template: > > def respondant(request): > > user = request.user > > if set(RESPONDANT_FIELDS).issubset(set([key for key,value in > request.POST.items()])): > form = RespondantForm(request.POST) > if form.is_valid(): > form.save() > template = "feedback/success.html" > else: > form = RespondantForm() > return render_to_response('feedback/index.html', { > 'form': form, > }) > > else: > key = request.REQUEST.get('key') > if key: > respondant = Respondant.objects.check_key(key) > else: > form = RespondantForm() > return render_to_response('feedback/index.html', { > 'form': form, > }) > > return render_to_response(template) This is an unusual structure for a form view, but the problem happens in the first `else` clause. Previously you've instantiated the form, passing it the POSTed values, and checked it for errors. But now you re-instantiate a *blank* form, which obviously won't have any errors attached to it. Instead of doing that, you should simply be passing the existing form object into the template - in other words, you don't need that `else` clause at all (I'm assuming that the extra indentation of `return render_to_response` is just a cut-and-paste error, and it's actually at the same level as the `if form.is_valid()` line.) -- 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-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: Form Validation
Here's the view template: def respondant(request): user = request.user if set(RESPONDANT_FIELDS).issubset(set([key for key,value in request.POST.items()])): form = RespondantForm(request.POST) if form.is_valid(): form.save() template = "feedback/success.html" else: form = RespondantForm() return render_to_response('feedback/index.html', { 'form': form, }) else: key = request.REQUEST.get('key') if key: respondant = Respondant.objects.check_key(key) else: form = RespondantForm() return render_to_response('feedback/index.html', { 'form': form, }) return render_to_response(template) On Jul 30, 11:44 am, Daniel Rosemanwrote: > On Jul 30, 4:42 pm, rupert wrote: > > > I'm trying to use this line of code in form validation, and it is not > > working: > > > {{ form.field_name.errors }} > > > The following lines do output: > > {{ form.filed_name}} > > {{ form.field_name.help_text }} > > > Any thoughts? Could it be something in the view? > > Very likely. Has the form been validated? > -- > 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-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: Form Validation
On Jul 30, 4:42 pm, rupertwrote: > I'm trying to use this line of code in form validation, and it is not > working: > > {{ form.field_name.errors }} > > The following lines do output: > {{ form.filed_name}} > {{ form.field_name.help_text }} > > Any thoughts? Could it be something in the view? Very likely. Has the form been validated? -- 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-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.
Form Validation
I'm trying to use this line of code in form validation, and it is not working: {{ form.field_name.errors }} The following lines do output: {{ form.filed_name}} {{ form.field_name.help_text }} Any thoughts? Could it be something in the view? Here is the index.html page: # {% extends "feedback/base.html" %} {% block content %} {{ form.event.errors }} Event you participated in: {{ form.event }} Your unit: {{ form.unit }} {{ form.unit.help_text }} Your name: {{ form.name }} {{ form.name.help_text }} Title {{ form.title }} {{ form.title.help_text }} Your email address: {{ form.email }} {{ form.email.help_text }} {% if form.name.errors %} {% for error in form.name.errors %} {{ error|escape }} {% endfor %} {% endif %} {{ form.errors }} {{ form.question_1 }} {{ form.question_2.errors }} {{ form.question_2 }} {{ form.question_3.errors }} {{ form.question_3 }} {{ form.question_4.errors }} {{ form.question_4 }} {{ form.question_5.errors }} {{ form.question_5 }} {{ form.comment_6.errors }} {{ form.comment_6 }} {{ form.comment_7.errors }} {{ form.comment_7 }} {{ form.comment_8.errors }} {{ form.comment_8 }} {{ form.comment_9.errors }} {{ form.comment_9 }} {{ form.comment_10.errors }} {{ form.comment_10 }} {% endblock content %} -- 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: field.label in template converts to lower case in 1.2.1
Actually - make that change to the rest of the field options too. The word wrap threw me off there at the end. On Jul 30, 8:16 am, Jasonwrote: > Looks like you are generating the fields in two different cases. > Here's the second one: > > self.fields[config.ConfigurationName] = > forms.ChoiceField( > choices=choicelist, > required=False) > > Change that to: > > self.fields[config.ConfigurationName] = > forms.ChoiceField( > label = > config.ConfigurationName, > choices=choicelist, > required=False) > > (and make the same change to the multiple select as well) > > Assuming the ConfigurationName has proper capitalization it should > work. > > On Jul 30, 5:26 am, Jeff Green wrote: > > > Here is my form class > > > class StationInfo( forms.Form): > > > def __init__( self, *args, **kwargs): > > super( StationInfo, self).__init__( *args, **kwargs) > > > request = args[1] > > selecttuple = "choice0", "--Select One--" > > > userid = threadlocals.get_current_user() > > user = '%s' % userid > > userrec = User.objects.get(username=user) > > projrecs = UserProj.objects.filter( User=userrec) > > self.projlist = [] > > phaselist = [] > > for proj in projrecs: > > self.projlist.append( proj.ProjectId) > > > # Get all the configurations for a station > > stationrec = request.session['stationrec'] > > configlist1 = Configuration.objects.filter( > > ConfigurationType='Station', AdditionalEquipFlag=False) > > configlist2 = Configuration.objects.filter( > > ConfigurationType='Station', > > AdditionalEquipFlag=True).order_by('ConfigurationName') > > configlist = list(chain(configlist1, configlist2)) > > > for config in configlist: > > config_str = '%s' % config > > foundconfig = True > > # Get station configuration record for given station > > configstr_list = [] > > try: > > stationconfiglist = StationConfig.objects.filter( > > > ConfigValueId__ConfigurationId__ConfigurationName=config.ConfigurationName, > > EndDate__isnull=True, > > StationId=stationrec > > ) > > if len(stationconfiglist) == 0: > > foundconfig = False > > else: > > for stationconfigrec in stationconfiglist: > > configstr = '%s' % stationconfigrec.ConfigValueId > > configstr_list.append( configstr) > > > except: > > foundconfig = False > > > # Get choice list > > choicelist = [] > > if config_str == 'Phase' or config_str == 'Project': > > configvalues = ConfigValues.objects.filter( > > > ConfigurationId__ConfigurationName=config.ConfigurationName > > ).order_by( 'ConfigValue') > > else: > > configvalues = ConfigValues.objects.filter( > > > ConfigurationId__ConfigurationName=config.ConfigurationName, > > ProjectId__in = self.projlist).order_by( 'ConfigValue') > > if not foundconfig: > > if config.MultiSelectFlag: > > choicelist.append( selectmoretuple) > > else: > > choicelist.append( selecttuple) > > select_fieldlist = [] > > allchoiceslist = [] > > for configrec in configvalues: > > configvalstr = '%s' % configrec > > allchoiceslist.append( configvalstr) > > choicestr = "choice%s" % str( configrec.id) > > choicetuple = choicestr, configrec.ConfigValue > > if configrec.ConfigValue in configstr_list: > > choicelist.insert( 0, choicetuple) > > select_fieldlist.append( choicestr) > > else: > > choicelist.append( choicetuple) > > > for stationconfigrec in stationconfiglist: > > configstr = str( stationconfigrec.ConfigValueId) > > # Tried if not in list but it gave incorrect result > > found = False > > for choice in allchoiceslist: > > if configstr == choice: > > found = True > > break > > if not found: > > choicestr = "choice%s" % str( > > stationconfigrec.ConfigValueId.id) > > choicetuple = choicestr, configstr > > choicelist.insert( 0,
Re: test's client.post says post but request.method says GET
On Jul 30, 3:28 am, Phlipwrote: > > What's the value of `self.url`? One possibility is that it doesn't end > > with a slash > > Ends with a slash. I'm now checking the response goodies, like > response.status, to see if any other redirections happen! Yup - a redirect. My colleagues left SSL turned on. I won't ask how to mock it in a test I'l just turn it off... -- 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: field.label in template converts to lower case in 1.2.1
Looks like you are generating the fields in two different cases. Here's the second one: self.fields[config.ConfigurationName] = forms.ChoiceField( choices=choicelist, required=False) Change that to: self.fields[config.ConfigurationName] = forms.ChoiceField( label = config.ConfigurationName, choices=choicelist, required=False) (and make the same change to the multiple select as well) Assuming the ConfigurationName has proper capitalization it should work. On Jul 30, 5:26 am, Jeff Greenwrote: > Here is my form class > > class StationInfo( forms.Form): > > def __init__( self, *args, **kwargs): > super( StationInfo, self).__init__( *args, **kwargs) > > request = args[1] > selecttuple = "choice0", "--Select One--" > > userid = threadlocals.get_current_user() > user = '%s' % userid > userrec = User.objects.get(username=user) > projrecs = UserProj.objects.filter( User=userrec) > self.projlist = [] > phaselist = [] > for proj in projrecs: > self.projlist.append( proj.ProjectId) > > # Get all the configurations for a station > stationrec = request.session['stationrec'] > configlist1 = Configuration.objects.filter( > ConfigurationType='Station', AdditionalEquipFlag=False) > configlist2 = Configuration.objects.filter( > ConfigurationType='Station', > AdditionalEquipFlag=True).order_by('ConfigurationName') > configlist = list(chain(configlist1, configlist2)) > > for config in configlist: > config_str = '%s' % config > foundconfig = True > # Get station configuration record for given station > configstr_list = [] > try: > stationconfiglist = StationConfig.objects.filter( > > ConfigValueId__ConfigurationId__ConfigurationName=config.ConfigurationName, > EndDate__isnull=True, > StationId=stationrec > ) > if len(stationconfiglist) == 0: > foundconfig = False > else: > for stationconfigrec in stationconfiglist: > configstr = '%s' % stationconfigrec.ConfigValueId > configstr_list.append( configstr) > > except: > foundconfig = False > > # Get choice list > choicelist = [] > if config_str == 'Phase' or config_str == 'Project': > configvalues = ConfigValues.objects.filter( > > ConfigurationId__ConfigurationName=config.ConfigurationName > ).order_by( 'ConfigValue') > else: > configvalues = ConfigValues.objects.filter( > > ConfigurationId__ConfigurationName=config.ConfigurationName, > ProjectId__in = self.projlist).order_by( 'ConfigValue') > if not foundconfig: > if config.MultiSelectFlag: > choicelist.append( selectmoretuple) > else: > choicelist.append( selecttuple) > select_fieldlist = [] > allchoiceslist = [] > for configrec in configvalues: > configvalstr = '%s' % configrec > allchoiceslist.append( configvalstr) > choicestr = "choice%s" % str( configrec.id) > choicetuple = choicestr, configrec.ConfigValue > if configrec.ConfigValue in configstr_list: > choicelist.insert( 0, choicetuple) > select_fieldlist.append( choicestr) > else: > choicelist.append( choicetuple) > > for stationconfigrec in stationconfiglist: > configstr = str( stationconfigrec.ConfigValueId) > # Tried if not in list but it gave incorrect result > found = False > for choice in allchoiceslist: > if configstr == choice: > found = True > break > if not found: > choicestr = "choice%s" % str( > stationconfigrec.ConfigValueId.id) > choicetuple = choicestr, configstr > choicelist.insert( 0, choicetuple) > select_fieldlist.append( choicestr) > > if config.MultiSelectFlag: > > self.fields[config.ConfigurationName] = > forms.MultipleChoiceField( > choices=choicelist, > required=False, > widget = > MyMultiSelectWidget(initial=select_fieldlist ))
Re: values with distinct not working as expected
You don't need order_by to get distinct values per se, but in this case you need to put it in to override whatever default ordering you have on your model (since any order_by fields will be included in the query and thwart your distinct()). On Jul 30, 3:52 am, tuxcanflywrote: > Thanks, that works! > > But I don't understand why I should order_by to get distinct values. > > On Jul 29, 3:59 pm, Subhranath Chunder wrote: > > > > > If you don't want to uniquify yourself, then why not simply do: > > User.objects.values('username').order_by('username').distinct() > > > or, going the way that were already heading, it would be: > > Visitor.objects.values('user__username').order_by('user__username'').distin > > ct() > > > Thanks, > > Subhranath Chunder. > > > On Thu, Jul 29, 2010 at 2:29 PM, tuxcanfly wrote: > > > I have this: > > > > class Visitor(models.Model): > > > user = models.ForeignKey(User) > > > .. > > > .. > > > > I'm trying to get the distinct usernames, so I did this: > > > > Visitor.objects.values("user__username").distinct() > > > > But this stil gives me duplicate usernames. Of course I could use a > > > flat values_list and uniquify the result, but... > > > > -- > > > 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 > > groups.com> > > > . > > > For more options, visit this group at > > >http://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: Need Help!
You could look here: http://djangopeople.net/us/ny/ Or try posting here: http://djangogigs.com/ or here: http://djangozen.com/jobs/ Hope that helps, Alex On Jul 29, 11:27 am, Kenwrote: > Looking for a django developer in the NYC area! > I would appreciate any help, if you know of anyone! > Thank you! > > Ken -- 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: Regex problem in urls
Based on the urls.py file you are showing us, it seems like /start/ should be a valid url. Are you running the dev server with automatic reloading? Sometimes you need to force a reload on it to see changes. (I normally notice that in the admin, but it could come up anywhere stuff gets cached in memory for performance on startup). Alex On Jul 29, 4:18 pm, Gordywrote: > I'm a rookie at Django so this is probably something obvious. > > My urls.py looks like this: > > from django.conf.urls.defaults import * > > # Uncomment the next two lines to enable the admin: > from django.contrib import admin > admin.autodiscover() > > urlpatterns = patterns('', > # Example: > # (r'^sunlight/', include('sunlight.foo.urls')), > > # Uncomment the admin/doc line below and add > 'django.contrib.admindocs' > # to INSTALLED_APPS to enable admin documentation: > (r'^admin/doc/', include('django.contrib.admindocs.urls')), > > # Uncomment the next line to enable the admin: > (r'^admin/(.*)', 'admin.site.root'), > (r'^start/', 'sunlight.start.views.index'), > (r'req/','sunlight.requests.views.index'), > ) > ~ > > When I hit the site, I get: > > Page not found (404) > Request Method: GET > Request URL: http://server2/start/ > > Using the URLconf defined in sunlight.urls, Django tried these URL > patterns, in this order: > > 1. ^admin/doc/ > 2. ^admin/(.*) > 3. ^[/]$ > 4. req/ > > The current URL, start/, didn't match any of these. > > So it looks like it isn't properly interpreting the regex on line 3. > > Any help would be 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-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: Re: Best way to find near people
A couple of possible optimizations: First, because cos is single valued over the range of possible angles (as measured from the center of the earth, 0 <= d <= PI) distance is monotonic with cos distance. So you can pre-calculate the cos of the distance, and compare the innder expression to that: th = cos(near_value_in_km / 6378.137) Also, pre-calculate lat as radians, sin of long, and cos of long, so that there's no chance that the database will perform these calculations once per row as opposed to once per query. Then: (cos_long * cos(radians(lattitude)) * cos(radians(longitude) - rad_lat) + sin_long * sin(radians(latitude) > th (Yes, greater than. Cos is max, +1, at minimum distance.) Far fewer trig functions per row. And if you're willing to denormalize, storing latitude as both its sin and cos, and longitude as its cos (possibly, further denormalization, also storing the original degree values to avoid dancing low order decimals in the UI), then you only need one trig functionper row. If you arrange to return the expression, you don't even have to recalculate it on the python side to get actual distance, if desired, for the items that are close enough (take acos and multiply by earth radius). Note that you can still sort on cos(distance) in the DB if you're interested in, for example, a closest first presentation. Applying the bounding box first means that you can avoid even that one cos for items that are outside the bounding box. On Fri, Jul 30, 2010 at 4:06 AM, Henrik Genssenwrote: > I use .extra(where=[where]) > > and something like this (measures km, not miles): > ( 6378.137 * acos( cos( radians(long) ) * cos( radians( latitude ) ) * cos( > radians( longitude ) - radians(lat) ) + sin( radians(long) ) * sin( radians( > latitude ) ) ) ) < 10 > > latitude and logitude are db-fields, 6378.137 the radius of the earth, > long/lat my current position, searches for objects in a 10 km circle > > regards > > Henrik > > >>reply to message: >>date: 30.07.2010 07:30:30 >>from: "Jani Tiainen" >>to: django-users@googlegroups.com >>subject: Re: Best way to find near people >> >>> On Jul 29, 2010, at 2:58 PM, Alexandre González wrote: >>> > Hi! >>> > >>> > I'm searching near people in my app. I'm doing it a this way: >>> > >>> > 37 people = Person.objects.all().exclude(user=request.user) >>> > 38 >>> > 39 near_people = list() >>> > 40 for person in people: >>> > 41 if self.is_near(me.coordinates, person.coordinates): >>> > near_people.append(person) >>> > >>> > Now, I'm getting all the the Person objects. This is a inefficient way. >>> > >>> > The coordinates are latitude/longitude coordinates, so I think in test >>> > the variation and get only latitude +/- 1 and longitude +/- 1 and after >>> > this, do the test exactly (the funcion is_near). >>> > >>> > But instead this, can I "draw" a circle and search only Person objects >>> > inside it? >>> >>> I'm not sure what database you are using, but if you are using PostgreSQL, >>> it has built-in geometric operators specifically for this kind of thing. >>> You might have to drop down into SQL, but in 1.2, that's nice and easy. >>> >>> The PostgreSQL documentation on this is at: >>> >>> http://www.postgresql.org/docs/8.4/interactive/datatype-geometric.html >>> -- >>> -- Christophe Pettus >>> ...@thebuild.com >> >>Or if spatial operations are really needed, why not to use real spatial >>database and GeoDjango (django.contrib.gis). Spatialite, Postgis, Mysql or >>oracle. All supports at spatial to some extent. And there you can do easily >>simple filtering: >> >>Person.objects.filter(person_coordinates__dwithin(me.coordinates, distance)) >> >>..and geodjango + spatial engine behind it will take care of all that complex >>stuff. >> >>Note: you can still use GEOS parts from geodjango to do calculations so you >>don't have to reinvent wheel if you want to keep coordinates as you already >>have. >> >>-- >> >>Jani Tiainen >> >>-- >>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. >> > > -- > 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. > > -- 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,
Re: generate cache by visiting protected links
On 30/07/2010 12:06, Jirka Vejrazka wrote: >> I still have 2 approaches i can take. > > I still believe that there is a 3rd option there - to bypass the > view / auth / login machinery completely :) > > > If your primary goal is to cache the statistics and the statistics > does not depend on the user that is logged in (you did pass a user > with pk=1 in one of your previous emails), then you don't really need > to call any view to cache the data. You can call the function that > calculates the statistics (that would cache the data internally within > the function), then call this function from anywhere upon start of > your webserver (or cron job, as mentioned before). > > As long as you have a global cache (i.e. memcached), this would work > very nicely and you would not have to do any urllib2 login magic. > > Let me give you a short example: > > def stats_top_callers_per_year(some_parameters_not_tied_to_a_specific_user): > cache_key = 'stats_top_callers_per_year' > data = cache.get(cache_key) > if data: > return data > # calculate the data somehow > cache.set(cache_key, data) # <- set appropriate timeout there > > > Then have small script called before (or shortly after) your web > server start, that would import this function from your code, hence > calculating the statistics. Then, as long as you use memcached, your > web would use the cached statistics every time the > stats_top_callers_per_year() would be called frmo your views. > > Jirka > Hi Jirka, your approach is better, and cleaner. I will do it that way. It boils down to caching the results of querysets rather than caching pages. I'll post the stats function i've been using to test all this: @check_can_view_stats @csrf_exempt def stats_top_callers_per_year(request): # Statistics for the top 30 callers # Choose different base ( & menu) according for staff or other user if ( request.user.is_staff ): extends_from = "management/base.html" else: extends_from = "management/public_base.html" # We'll use a simple class that will serve as the base for the individual data class Stats(object): pass stats_all = {} # We want the last 5 years current_year = datetime.datetime.now().year archive_year = current_year - 4 years = xrange(archive_year, current_year+1) for year in years: stats_year = [] counts = {} # Initialize count dict # If we don't do this, we get a KeyError for user in User.objects.all(): counts[user]=0 # Count the times an user has called (called initiator here) for i in Call.objects.filter(date_created__year=year): for _init in i.initiator.all(): counts[_init] += 1 # Sort the dictionary count_sorted = sorted(counts.items(), lambda x, y: cmp(x[1], y[1]), reverse=True) # Make the stats of the top 30 users ready for the template for user_stat in count_sorted[0:30]: if ( user_stat[1] > 0 ): st = Stats() st.calls = user_stat[1] st.user = user_stat[0] stats_year.append(st) stats_all[year]=stats_year stats_sorted = sorted(stats_all.items(), lambda x, y: cmp(x[0], y[0]), reverse=True) return render_to_response('management/stats.html', {'extends_from': extends_from, 'stats_year': stats_sorted}, context_instance=RequestContext(request)) I'm sure there is still room for improving the way i construct my data but i haven't yet reached that phase in the project :) Caching the stats_sorted data would be enough i think. I calculate here which users have been bothering our ICT the most. It's a vital stat :) ;) Also, my 1ste approach comes with a hitch. According to who logs in, you get a different menu and there is also a login button with the username on it. This is also cached so when you visit the stats page under your own user, you see the stats correcty but the logout part contains the administrator name instead of your own. In other words, the menu & login/logout button needs to be excluded from cache. As i've found out, there is no standard way of doing that in Django and you need to use a custom tag & middleware: http://www.holovaty.com/writing/django-two-phased-rendering/ I've tried to set it up but it failed so far. As it turns out, your method is clearer, simpler and does what i want :) Building a nice decorator from it that takes the function name as key would be ideal so i'll do it that way. Thanks, Benedict -- 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.
filebrowser w/ grappelli
hi group. I've got filebrowser working great with grappelli. It uploads images and does the sizes automatically. I have a question though. How do you choose the size you want to to use from the filebrowser popup window when you want to insert an image? I don't see any way to do it. Does anyone know? -- 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: Python/Django hosting
On Thu, Jul 29, 2010 at 1:22 PM, kostiawrote: > Thanks, I already know about webfraction. Great site. > > If anyone can provide cheaper solution, hosted in Europe, please write > me. > > -- http://lmgtfy.com/?q=django+hosting+europe=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.
ManyToMany to languages
I need to put a manytomany that points to a list of languages. I need to create another language model or I can use a django languages one? -- Alessandro Ronchi http://www.soasi.com Hobby & Giochi http://hobbygiochi.com http://www.facebook.com/hobbygiochi -- 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.
[SOLVED] Re: Filtering within a ModelForm
Hi Derek, Thanks for your help -- I had tried both of those but couldn't get them to work with generic views. In the end I just abandoned the generic view and used the __init__() approach and things worked. -- Casey On 07/28/2010 09:35 AM, derek wrote: On Jul 26, 6:52 pm, "Casey S. Greene"wrote: Does anyone have a hint for this (or an idea of where to get started in the documentation)? This seems relatively simple so my best guess is that there is something that I am just missing. Thanks! -- Casey On 07/22/2010 10:16 AM, Casey S. Greene wrote: I am trying to figure out a reasonable way to filter using a queryset within a ModelForm. In a simple example, I have three models (A, B, and C). C has many A and B A and B have a many to many relationship. Assume that some instances of C and instances of B already exist. I am using the create_object generic view to allow users to create instances of A but not to select associated Bs. I'm then using update_object generic view to allow users to select the Bs associated with A. I've created a class that inherits from forms.ModelForm that defines the form. In that I have forms.ModelMultipleChoiceField() for selecting associated Bs. What I want to do is use the queryset to filter to only show those Bs that share C with this instance of A. I am confused as to how to do this type of query while passing a form_class from the update_object generic view. I have tried doing this in __init__() but I get a TypeError that the form is not callable when I try to pass arguments. Thanks in advance for your help and time, -- Casey And another one: http://code-blasphemies.blogspot.com/2009/04/dynamically-created-modelmultiplechoice.html -- 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.
Show mail instead user name in ForeignKey at admin
Hi! When I'm using user as ForeignField in some of my models I get a box with the username, can I override this with the mail instead the username? I've tested making a Proxy class, but I think that the proxy classes isn't for this. I heard about MonkeyPatch but I don't know how to use it, or if it's really the best way to do it. Thanks! Álex González -- Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt and/or .pptx http://mirblu.com -- 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: django autocomplete search with jQuery
I actually just set this up last weekend. I used this link to understand how to do it http://lethain.com/entry/2007/dec/01/using-jquery-django-autocomplete-fields/ I also found a plugin that takes most of the work off of you from developing the feature. http://bitbucket.org/tyrion/django-autocomplete/overview On Jul 30, 1:34 am, Joel Klabowrote: > I have been looking around for some examples but I can't find anything > recent. This is my first AJAX experience so I would love to just see > an example because it's not quite making sense to me. Does anyone know > of a tutorial? Or have some code samples I could check out? I have > checked google btw. -- 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.
[SOLVED] Re: Django Dev server doesn't reflect changes
On Jul 30, 10:33 am, Samuel Baldwinwrote: > Try clearing any server or browser caches first. > > -- > Samuel Baldwin - logik.li -- 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: Raw sql and admin site
# model class class Category(models.Model): CATEGORY_SEPARATOR = "." name = models.CharField(_('name'), max_length=255) idname = models.CharField(_('idname'), max_length=255, db_index=True, unique=True,) prio = models.IntegerField(_('prio'), default=0) description = models.TextField(_('description'), null=True, blank=True) materialised_path = models.TextField(_('materialised path'),null=True, db_index=True, blank=True) parent_category = models.ForeignKey("self", null=True, blank=True, help_text=_('Set if category should be child of other category')) category_container = models.ForeignKey(CategoryContainer, verbose_name=_('category container'), null=True, blank=True, help_text="In which box/ filter category should be visible") # admin class class CategoryAdmin(admin.Admin): list_display = ['id', 'name', 'parent_category', 'category_container', 'materialised_path'] list_display_links = ['id', 'name'] prepopulated_fields = {"idname": ("name",)} ordering = ["-order_path"] fieldsets = ( ('Base data', {'fields': (('name', 'idname'), 'description',)}), ('Relations', {'fields': ('parent_category', 'category_container')}), ('Additional data', {'fields': (('prio'),), 'classes': ('collapse',) }), ) def queryset(self, request): # below 2 lines work # categories = models.Category.objects.all() # or # categories = models.Category.objects.select_related('category_container').all() # below doesn't work categories = models.Category.objects.raw('SELECT * FROM category ORDER BY materialised_path using ~<~') return categories I use materialised_path because I have list of categories and related products Category 1 data name = 'Audi' materialised_path = 1 Category 2 data name = 'A4' materialised_path = 1.2 Category 3 data name = 'B7 (2004-2007)' materialised_path = 1.2.3 Category 4 data name = 'B7 (2004-2007) 1.9 TDI' materialised_path = 1.2.3.4 Product 1 data name = "AUDI A4 1.9 TDI 116 KM" materialised_path = 1.2.3.4 Product 2 data name = "AUDI A4 1.9 TDI 200 KM" materialised_path = 1.2.3.4 so now i can get all products or children of category Audi or A4 children = Category.objects.filter(materialised_path__startswith = audi_path) products = Product.objects.filter(materialised_path__startswith = audi_path) My problem is to show ManyToMany relations between products and categories in right order to easy use via Admin interface. I need something like: -Audi (materialised_path: 1) ---A4 (materialised_path: 1.2) --B7 (2004-2007) (materialised_path: 1.2.3) -BMW (materialised_path: 10) ---3 series (materialised_path: 10.11) But postgresql without ~<~ operator gets me: -Audi (materialised_path: 1) -BMW (materialised_path: 10) ---3 series (materialised_path: 10.11) ---A4 (materialised_path: 1.2) --B7 (2004-2007) (materialised_path: 1.2.3) eg. Depth of materialised path is count of char "-" so if i use sql with order by clause materialised_path i can get that ordering, but in postgresql i need to use operator ~*~ to get correct ordering, because my database works with utf cluster. And wheh I try to use the operator I got below error: Database error Something's wrong with your database installation. Make sure the appropriate database tables have been created, and make sure the database is readable by the appropriate user. Any ideas what I do wrong? > > Can you show the exact code you are currently using to try and use > this query in the admin, and the actual error you get? > -- > 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-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: Best way to present N items in table row for list
On 29 июл, 12:08, Roald de Vrieswrote: > First: list is a very unlucky name for a parameter, since it's the > type of [] > > Second: list comprehension rules! > > def groupListByRow(list): > return [lst[start:start+5] for start in range(0, len(lst), 5)] > > Cheers, Roald Perfect This is why people use Python Simple, short, elegant Finally i will use Roald's solution. The transformation in template is possible, but not so clear. Thanks to all for their help. -- 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: field.label in template converts to lower case in 1.2.1
Here is my form class class StationInfo( forms.Form): def __init__( self, *args, **kwargs): super( StationInfo, self).__init__( *args, **kwargs) request = args[1] selecttuple = "choice0", "--Select One--" userid = threadlocals.get_current_user() user = '%s' % userid userrec = User.objects.get(username=user) projrecs = UserProj.objects.filter( User=userrec) self.projlist = [] phaselist = [] for proj in projrecs: self.projlist.append( proj.ProjectId) # Get all the configurations for a station stationrec = request.session['stationrec'] configlist1 = Configuration.objects.filter( ConfigurationType='Station', AdditionalEquipFlag=False) configlist2 = Configuration.objects.filter( ConfigurationType='Station', AdditionalEquipFlag=True).order_by('ConfigurationName') configlist = list(chain(configlist1, configlist2)) for config in configlist: config_str = '%s' % config foundconfig = True # Get station configuration record for given station configstr_list = [] try: stationconfiglist = StationConfig.objects.filter( ConfigValueId__ConfigurationId__ConfigurationName=config.ConfigurationName, EndDate__isnull=True, StationId=stationrec ) if len(stationconfiglist) == 0: foundconfig = False else: for stationconfigrec in stationconfiglist: configstr = '%s' % stationconfigrec.ConfigValueId configstr_list.append( configstr) except: foundconfig = False # Get choice list choicelist = [] if config_str == 'Phase' or config_str == 'Project': configvalues = ConfigValues.objects.filter( ConfigurationId__ConfigurationName=config.ConfigurationName ).order_by( 'ConfigValue') else: configvalues = ConfigValues.objects.filter( ConfigurationId__ConfigurationName=config.ConfigurationName, ProjectId__in = self.projlist).order_by( 'ConfigValue') if not foundconfig: if config.MultiSelectFlag: choicelist.append( selectmoretuple) else: choicelist.append( selecttuple) select_fieldlist = [] allchoiceslist = [] for configrec in configvalues: configvalstr = '%s' % configrec allchoiceslist.append( configvalstr) choicestr = "choice%s" % str( configrec.id) choicetuple = choicestr, configrec.ConfigValue if configrec.ConfigValue in configstr_list: choicelist.insert( 0, choicetuple) select_fieldlist.append( choicestr) else: choicelist.append( choicetuple) for stationconfigrec in stationconfiglist: configstr = str( stationconfigrec.ConfigValueId) # Tried if not in list but it gave incorrect result found = False for choice in allchoiceslist: if configstr == choice: found = True break if not found: choicestr = "choice%s" % str( stationconfigrec.ConfigValueId.id) choicetuple = choicestr, configstr choicelist.insert( 0, choicetuple) select_fieldlist.append( choicestr) if config.MultiSelectFlag: self.fields[config.ConfigurationName] = forms.MultipleChoiceField( choices=choicelist, required=False, widget = MyMultiSelectWidget(initial=select_fieldlist )) else: print 'config name is ', config.ConfigurationName self.fields[config.ConfigurationName] = forms.ChoiceField( choices=choicelist, required=False) if config.ExpireFlag: for stationconfigrec in stationconfiglist: config_valuestr = '%s' % stationconfigrec.ConfigValueId print 'config value string is ', config_valuestr fieldname = ( config_valuestr + ' ' + config.ConfigurationName + ' CalibrationDueDate (US/Central Time)') print 'field name is ', fieldname if stationconfigrec.ExpireDate == None: self.fields[fieldname] = forms.SplitDateTimeField( required=False,
Re: moving to django 1.2.1
I cover some of the new changes in Django 1.2 in this article: http://www.tiemonster.info/a/24005/ Most of this information comes straight from the changelist. Others were things that the core developers must have assumed were common sense, but that I didn't think about when upgrading. If you run across anything that's not on the list, let me know and I'll update the article. -Mark On Jul 29, 3:41 am, knightwrote: > Thank you all for the links and advises. > It really helps me. > > Regards, Alex A. > > On Jul 29, 10:32 am, Russell Keith-Magee > wrote: > > > On Wed, Jul 28, 2010 at 9:29 PM, Massimiliano Ravelli > > > wrote: > > > On Jul 28, 3:13 pm, knight wrote: > > >> What are the minimal changes that I need to make in order to work with > > >> 1.2.1? > > > > Did you have a look > > > athttp://code.djangoproject.com/wiki/BackwardsIncompatibleChanges > > > ? > > > As it says at the top of that wiki page, that page documents the > > backwards incompatible changes that were made in the leadup to Django > > 1.0. > > > If you want migration notes for Django 1.1 or 1.2, you should consult > > the relevant release notes: > > > [1]http://docs.djangoproject.com/en/dev/releases/1.1/ > > [2]http://docs.djangoproject.com/en/dev/releases/1.2/ > > > 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-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: Django Dev server doesn't reflect changes
Try clearing any server or browser caches first. -- Samuel Baldwin - logik.li -- 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: test's client.post says post but request.method says GET
> What's the value of `self.url`? One possibility is that it doesn't end > with a slash Ends with a slash. I'm now checking the response goodies, like response.status, to see if any other redirections happen! -- 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: Raw sql and admin site
On Jul 29, 11:38 pm, Spokssswrote: > Hi, > > I try to use raw sql in admin site, it is possible somehow? > > I use postresql and have some problem with ordering. > > I have in database something like: > Category(id=1, name='first', parent_category=None, > materialised_path='1') > Category(id=2, name='child1 of first', parent_category=1, > materialised_path='1.2') > Category(id=1, name='child2 of first', parent_category=1, > materialised_path='1.3') > ... > Category(id=10, name='second', parent_category=None, > materialised_path='10') > > and now if i use normal sql 'select name, materialised_path from > category order by materialised_path' > and i get: > first 1 > second 10 > child1 of first 1.2 > child2 of first 1.3 > > but i need: > first 1 > child1 of first 1.2 > child2 of first 1.3 > second 10 > > because postgres is set to use utf collate, so in this moment i try > use ~<~ operator in raw query: > > categories = models.Category.objects.raw('''SELECT "category"."id", > "category"."name", "category"."idname", "category"."prio", > "category"."description", "category"."materialised_path", > "category"."parent_category_id", "category"."category_container_id" > FROM "category ORDER BY materialised_path using ~<~''') > > of course in def queryset(self, request) of CategoryAdmin. > > But I get database error, I think admin not supports raw query or I > use it not correct in this place. > > Do You know how can I use "~<~" in admin site? > > regards Can you show the exact code you are currently using to try and use this query in the admin, and the actual error you get? -- 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-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: generate cache by visiting protected links
> I still have 2 approaches i can take. I still believe that there is a 3rd option there - to bypass the view / auth / login machinery completely :) If your primary goal is to cache the statistics and the statistics does not depend on the user that is logged in (you did pass a user with pk=1 in one of your previous emails), then you don't really need to call any view to cache the data. You can call the function that calculates the statistics (that would cache the data internally within the function), then call this function from anywhere upon start of your webserver (or cron job, as mentioned before). As long as you have a global cache (i.e. memcached), this would work very nicely and you would not have to do any urllib2 login magic. Let me give you a short example: def stats_top_callers_per_year(some_parameters_not_tied_to_a_specific_user): cache_key = 'stats_top_callers_per_year' data = cache.get(cache_key) if data: return data # calculate the data somehow cache.set(cache_key, data) # <- set appropriate timeout there Then have small script called before (or shortly after) your web server start, that would import this function from your code, hence calculating the statistics. Then, as long as you use memcached, your web would use the cached statistics every time the stats_top_callers_per_year() would be called frmo your views. Jirka -- 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: generate cache by visiting protected links
On 29/07/2010 18:48, David De La Harpe Golden wrote: > On 29/07/10 16:58, Benedict Verheyen wrote: > >> So calling a thread once from within a view is not safe ? > > Depends on what your expectations are... > > I haven't managed to dig up the paragraph discussing the issue that I > recall existing. I've a strong feeling it was by Graham Dumpleton, he > mentions in passing here: > > http://groups.google.com/group/django-users/msg/e6e6b182fcd23d39 > > "You also don't have to deal with possibility of Apache killing off one > its processes, which might contain running jobs, when it is recycling > its processes." > > but there was a somewhat more detailed writeup somewhere else. > >> I'm planning on using Apache for production. > > Not a reason not to, just a reason not to use that particular approach > when doing so. > Thanks for the info, i'll put the code outside the view in an external file so i don't get unwanted behaviour. Regards, Benedict -- 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: generate cache by visiting protected links
On 29/07/2010 21:10, Jirka Vejrazka wrote: >> That's why i asked on what Django uses as a key to set and entry in the >> cache. >> If i generate the page and put it on the cache and then rely on Django to >> get it, >> the key i use needs to be the same as Django uses otherwise the page isn't >> found in the >> cache and the page is generated again and then cached by Django. >> And that's just what i want to avoid. >> I'm happy to leave the caching to Django, i just want to "help" cache it >> initially :) > > OK - now I see what you're trying to achieve :) > > What is slow for you? Is it the data calculation, or actualy > constructing the HTML page from the data (read:context) and page > template? > > If it's the former, I'd still cache inside the function that > calculates the data (with a fixed string key) to get the "transparency > of the program". Using the "hack" with the cache key you plan to use > sounds clever, but a bit difficult to pick up if someone else needs to > read and understand the code later. > > Just my 2 cents :) > > Jirka > The actual data calculation is slowest. The HTML page construction isn't fast either but i can live with that. Since putting the cache code inside my view could eventualy lead to problems, i'm going to take it outside the view and put it in a seperate file. I still have 2 approaches i can take. The first using urllib2 to retrieve the page. I just tested this and i can login to the site and open the correct url. I'll paste the code here as it shows how to login to a site and setting up a HTTPCookieProcessor so subsequent calls to the site don't complain about not being logged in: import urllib2, urllib stats_url = 'http://calltracking:8000/management/statistics/top/user/yearly/' login_url = "http://calltracking:8000/accounts/login/; username = 'xyz' password = '123' if __name__ == "__main__": # Log in to the site o = urllib2.build_opener( urllib2.HTTPCookieProcessor() ) urllib2.install_opener(o) p=urllib.urlencode({"username" : username, "password" : password}) f=o.open(login_url, p) data=f.read() f.close() # Now open the protected statistics page pagehandle = o.open(stats_url) data = pagehandle.read() pagehandle.close() # Not necessary, but to verify: fp = file(r"""c:\test.html""","w") fp.write(data) fp.close() Second approach is to use Django to access the view function and store the result in cache. You make a very good point about the transparency. I haven't thought about it and it's a very good reason to set/get the pages in cache as it would indeed be clear what i'm trying to achieve. What i would do then is make a decorator where i cache the page or get it. If i can get the urllib approach to fully work as intended, i can use the default Django caching. If not i'll use the 2nd approach and both would be from an external file that i can then schedule. Regards, Benedict -- 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: LANGUAGES var isn't in all views
On Fri, Jul 30, 2010 at 11:14:42AM +0200, Alexandre González wrote: > If I add: > > import settings > LANGUAGES=settings.LANGUAGES > > and return it in the render_to_response it works perfectly, but can I > automatice this in all views? Sure, it works for me without passing LANGUAGES explicitly. I'm afraid you'll have to read render_to_response to find out why. With kind regards, Baurzhan. -- 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: LANGUAGES var isn't in all views
If I add: import settings LANGUAGES=settings.LANGUAGES and return it in the render_to_response it works perfectly, but can I automatice this in all views? On Fri, Jul 30, 2010 at 10:55, Baurzhan Ismagulovwrote: > On Thu, Jul 29, 2010 at 11:52:31PM +0200, Alexandre González wrote: > > 42 {% for lang in LANGUAGES %} > ... > > It works perfectly in some webs, but in others the var LANGUAGES isn't > > provide automatically, do i need to send it in the views? > > I don't know whether it's relevant, but do you {% load i18n %} in your > templates? I also pass context_instance=RequestContext(request) from the > views, works fine for me. > > With kind regards, > Baurzhan. > > -- > 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. > > -- Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt and/or .pptx http://mirblu.com -- 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: LANGUAGES var isn't in all views
On Thu, Jul 29, 2010 at 11:52:31PM +0200, Alexandre González wrote: > 42 {% for lang in LANGUAGES %} ... > It works perfectly in some webs, but in others the var LANGUAGES isn't > provide automatically, do i need to send it in the views? I don't know whether it's relevant, but do you {% load i18n %} in your templates? I also pass context_instance=RequestContext(request) from the views, works fine for me. With kind regards, Baurzhan. -- 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: test's client.post says post but request.method says GET
On Jul 30, 1:18 am, Phlipwrote: > Django aficionados: > > Here's my test code: > > from django.test.client import Client > self.client = Client() > from django.core.files.base import ContentFile > file_content = ContentFile(sample_inventory_update_cvs()) > file_content.name = 'response.csv' > > response = self.client.post( self.url, > data={'csv_file':file_content} ) > > Disregard all that ContentFile nonsense (unless it's causing the bug). > > Inside the action code, I want to distinguish GETting from POSTing. > One paints the page and the other absorbs new form data, as usual. > > However, when I print request.method, I get GET. > > Is this a bug in Client? or in (ahem) my comprehension? > > -- > Phlip > http://c2.com/cgi/wiki?ZeekLand What's the value of `self.url`? One possibility is that it doesn't end with a slash, and you have the APPEND_SLASH setting set to True (the default), so Django is redirecting from '/foo' to '/foo/'. A redirected POST ends up as a GET. -- 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-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: UnicodeEncodeError
On Jul 29, 11:27 pm, Ericwrote: > I am getting this error in the Django Administration section when I > add an entry for a Dashboard object. > > When I return to the item in the Admin section, the record has been > added and it displays correctly in the list of Dashboard objects. When > I click on it, it shows correctly. Only when I add a new one or save > one does that happend. And, I noticed that the history is not > populated. > > The traceback is: > > Environment: > > Request Method: POST > Request URL:http://127.0.0.1:8000/admin/dashboard/dashboard/1/ > Django Version: 1.2.1 > Python Version: 2.6.2 > Installed Applications: > ['django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.messages', > 'django.contrib.admin', > 'ManagementReview.dashboard'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware') > > Traceback: > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/core/handlers/base.py" in get_response > 100. response = callback(request, > *callback_args, **callback_kwargs) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/contrib/admin/options.py" in wrapper > 239. return self.admin_site.admin_view(view)(*args, > **kwargs) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/utils/decorators.py" in _wrapped_view > 76. response = view_func(request, *args, > **kwargs) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/views/decorators/cache.py" in > _wrapped_view_func > 69. response = view_func(request, *args, **kwargs) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/contrib/admin/sites.py" in inner > 190. return view(request, *args, **kwargs) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/utils/decorators.py" in _wrapper > 21. return decorator(bound_func)(*args, **kwargs) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/utils/decorators.py" in _wrapped_view > 76. response = view_func(request, *args, > **kwargs) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/utils/decorators.py" in bound_func > 17. return func(self, *args2, **kwargs2) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/db/transaction.py" in > _commit_on_success > 299. res = func(*args, **kw) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/contrib/admin/options.py" in > change_view > 901. self.log_change(request, new_object, > change_message) > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/contrib/admin/options.py" in log_change > 443. object_repr = force_unicode(object), > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/django/utils/encoding.py" in force_unicode > 66. s = unicode(s) > File "/Users/Eric/Documents/DjangoProjects/ManagementReview/../ > ManagementReview/dashboard/models.py" in __unicode__ > 47. return u"%s" % self.name.decode('utf-8') > File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/encodings/utf_8.py" in decode > 16. return codecs.utf_8_decode(input, errors, True) > > Exception Type: UnicodeEncodeError at /admin/dashboard/dashboard/1/ > Exception Value: ('ascii', u"Eric's Nifty D\xe4shboard Entry", 14, 15, > 'ordinal not in range(128)') > > The model looks like this: > > class Dashboard(models.Model): > name = models.CharField("Dashboard name",max_length=100) > fiscal_year = models.IntegerField("Fiscal year") > region = models.CharField("Region", max_length=30) > review_date = models.DateField("Review date") > date_completed = models.DateField("Date Completed") > > def __unicode__(self): > return u"%s" % self.name.decode('utf-8') > > Can somebody help me figure out what is going on here? > > Thanks > Eric This wouldn't necessarily cause that error, but your __unicode__ method is unnecessarily complicated. All model elements retrieved from the db are already unicode, so there's no reason to 'decode' from utf-8. The method
RE: Re: Best way to find near people
I use .extra(where=[where]) and something like this (measures km, not miles): ( 6378.137 * acos( cos( radians(long) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(lat) ) + sin( radians(long) ) * sin( radians( latitude ) ) ) ) < 10 latitude and logitude are db-fields, 6378.137 the radius of the earth, long/lat my current position, searches for objects in a 10 km circle regards Henrik >reply to message: >date: 30.07.2010 07:30:30 >from: "Jani Tiainen">to: django-users@googlegroups.com >subject: Re: Best way to find near people > >> On Jul 29, 2010, at 2:58 PM, Alexandre González wrote: >> > Hi! >> > >> > I'm searching near people in my app. I'm doing it a this way: >> > >> > 37 people = Person.objects.all().exclude(user=request.user) >> > 38 >> > 39 near_people = list() >> > 40 for person in people: >> > 41 if self.is_near(me.coordinates, person.coordinates): >> > near_people.append(person) >> > >> > Now, I'm getting all the the Person objects. This is a inefficient way. >> > >> > The coordinates are latitude/longitude coordinates, so I think in test >> > the variation and get only latitude +/- 1 and longitude +/- 1 and after >> > this, do the test exactly (the funcion is_near). >> > >> > But instead this, can I "draw" a circle and search only Person objects >> > inside it? >> >> I'm not sure what database you are using, but if you are using PostgreSQL, >> it has built-in geometric operators specifically for this kind of thing. >> You might have to drop down into SQL, but in 1.2, that's nice and easy. >> >> The PostgreSQL documentation on this is at: >> >> http://www.postgresql.org/docs/8.4/interactive/datatype-geometric.html >> -- >> -- Christophe Pettus >>x...@thebuild.com > >Or if spatial operations are really needed, why not to use real spatial >database and GeoDjango (django.contrib.gis). Spatialite, Postgis, Mysql or >oracle. All supports at spatial to some extent. And there you can do easily >simple filtering: > >Person.objects.filter(person_coordinates__dwithin(me.coordinates, distance)) > >..and geodjango + spatial engine behind it will take care of all that complex >stuff. > >Note: you can still use GEOS parts from geodjango to do calculations so you >don't have to reinvent wheel if you want to keep coordinates as you already >have. > >-- > >Jani Tiainen > >-- >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. > -- 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: values with distinct not working as expected
Thanks, that works! But I don't understand why I should order_by to get distinct values. On Jul 29, 3:59 pm, Subhranath Chunderwrote: > If you don't want to uniquify yourself, then why not simply do: > User.objects.values('username').order_by('username').distinct() > > or, going the way that were already heading, it would be: > Visitor.objects.values('user__username').order_by('user__username'').distin > ct() > > Thanks, > Subhranath Chunder. > > > > On Thu, Jul 29, 2010 at 2:29 PM, tuxcanfly wrote: > > I have this: > > > class Visitor(models.Model): > > user = models.ForeignKey(User) > > .. > > .. > > > I'm trying to get the distinct usernames, so I did this: > > > Visitor.objects.values("user__username").distinct() > > > But this stil gives me duplicate usernames. Of course I could use a > > flat values_list and uniquify the result, but... > > > -- > > 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 > groups.com> > > . > > For more options, visit this group at > >http://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: Django Dev server doesn't reflect changes
On Friday, July 30, 2010 10:55:13 am barun wrote: > I've restarted the server, browser. Do I need to do anything else? browser cache? -- Regards Kenneth Gonsalves Senior Associate NRC-FOSS at AU-KBC -- 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.