Re: Recommendations for a Django development book?
You can always check out the free online Django book at: http://www.djangobook.com/ There is the 1.0 version (outdated) and a free web-preview of the 2nd edition available. In addition to books, the documentation for Django is pretty fantastic to learn from for a beginner. This is located at: http://docs.djangoproject.com/en/dev/ Dan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Don't understand ModelForm
This may not be helpful but here is how I usually go about processing model forms: class Partner(models.Model): # this is your model, DB fields go in here # This is your model form class PartnerForm(forms.ModelForm): class Meta: model = Partner # This is the view that displays a new partner form or processes the form def new(request): form = PartnerForm() if request.method=="POST": # if there is a post, they are sending in the form so re- create the form from the post data form = PartnerForm(request.POST) if form.is_valid(): p = form.save() # save the form and store the resulting Partner object in p return HttpResponseRedirect("/success") # always redirect after processing a form to revent refresh spam # if we got to this point it means it wasn't a POST and we didn't process a form, or the form was invalid # either way, render whatever we had with errors and what not return render_to_response('new_partner_template.html', {'form': form}) # This is a view to edit and existing parter def edit(request, id): # ID is the partners identifying number such as primary key, SSN, whatever you want p = get_object_or_404(Partner, pk=id) # this will throw a 404 if they requested an invalid partner form = PartnerForm(instance=p) # create a form pre-populated with the partner data we just loaded if request.method=='POST': # now process the submitted form form = PartnerForm(request.POST, instance=p) # this creats a form using the database data AND the post data if form.is_valid(): p = form.save() return HttpResponseRedirect('/success') # if we got down here, they didn't submit the form, or they did and there were errors, so render it back return render_to_response('my_template.html', {'form': form}) This is how I do it, If you have any further questions I can try to help. Please note this code was off the top of my head, so it may not compile "out of the box" Dan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Don't understand ModelForm
What do you mean by having the ID "in" the form? I don't quite understand what you are trying to do. On Jul 21, 4:15 pm, mettwoch wrote: > Ok, I come back to what I wrote before. If the partner already exists > it has an id (primary-key or whatever). If it doesn't exist it has no > id. I'd just like to have the id in the form. Is it a bug, is > something missing here or am I completely on the wrong track. That's > basic database form handling. Well I could fallback to using Form > instead of ModelForm and maybe I'll manage to get that id in the form > as a hidden field or whatever, but I wonder how such basic things seem > impossible with the ModelForm. > > Thanks for Your patience > > Marc > > On Jul 21, 9:55 pm, Shawn Milochik wrote: > > > > > On Jul 21, 2009, at 3:39 PM, mettwoch wrote: > > > > Sorry to insist, but that's what I don't understand here. How can I > > > know that the partner that is 'posted' is new or not? I really become > > > crazy here. I can't believe after all the good things I've discovered > > > in Django that this can be so hard. > > > Okay, thanks for clarifying. > > > Well, you can have the partner identified in the URL by a slug or > > something, for one. That's probably the easiest way. You do need to > > track it somehow, starting when you pull the instance from the > > database to populate the ModelForm. Otherwise, how can you know that > > it's someone new versus someone with the same details? > > > The way I'm doing it is by having separate views and urls for editing > > and creating a new entry. But in any case you have to write something > > somewhere when you are pulling an existing record. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Don't understand ModelForm
Oh I gotcha now. Django model forms by default do not represent auto fields (ID's) because it wouldn't make much sense for a user to be able to edit the PK in a form. Having said that, I do understand why you need to be able to see the PK. I shown in my example, I personally prefer to represent the PK in the url so something like http://localhost/Partner/Edit/3 would be sent to the view: def edit(request, id): If you do not like doing it that way, you just have to pass the ID of the partner object into your template. SInce you are saving your partner object in session you can get access to it right away in the template. Just alter your template a bit: {{ form.as_Table}} Now you ahve Id available in your post data, so you can do your check. if request.POST.get("partner_id"): continue processing --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Pass template tags through TextField?
That shouldn't be a problem, after all templates are just strings as are textfields. If you have a model with your textfield in it as so: class MyModel(models.Model): template = models.TextField() and you have a view which renders the template defined in the next field def my_view(request): m = MyModel.objects.get(pk=1) # for example the first one t = Template(m.template) #this creates a template from your string in the model c = Context({'form': form, etc.. #any context to go into the template}) # now you can just return the rendered template as html return HttpResponse(t.render(c)) For more info refer to: http://docs.djangoproject.com/en/dev/ref/request-response/ Cheers, Dan On Jul 22, 12:49 pm, Ogre wrote: > I have a model where I need to be able to insert template tags into a > TextField in the admin as part of the content and then have them > rendered properly on the front-end. > > Can this be done? And if so, can someone recommend a method? I > understand the security concerns of opening that field up to python. > > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django-registration and RegistrationFormUniqueEmail subclass
The stuff in the brackets are the optional arguments passed to the "register" view. You can read the documentation about the view at: http://bitbucket.org/ubernostrum/django-registration/src/b360801eae96/docs/views.txt Alternatively you can check out the code as well. Cheers, Dan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Getting data from Django ModelForm ?
Take a peek at the Django forms documentation, specifically the ModelChoiceField and ModelMultipleChoiceField, the docs are at: http://docs.djangoproject.com/en/dev/ref/forms/fields/ These fields allow you to specify a queryset to populate your form select fields, this queryset can be the list of articles for the logged in user. Cheers, Dan On Jul 25, 3:56 pm, Asinox wrote: > Hi guys, i have a problem with ModelForm, the problem is that in the > user private area there is a Form (ModelForm), but in this Form i have > a Select, this select show the parent articles , so the problem is > that the Select show all parent articles, from all users > > How ill just show the parent articles of the logged user? bcz the > Select in the Model is a ForeignKey from another table. > > There's a method that ill write in the Model or in the ModelForm? > > sorry with my english --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: '_CheckLogin' object has no attribute 'objects' ??
Looks just like you have an error in your programming, the name of your view is "Dpatas", then you attempt to later call "Dpatas.objects.filter()" as if Dpatas was a model. The _CheckLogin is coming from your use of the @login_required decorator I would imagine. Hopefully that helps, Dan On Jul 25, 8:16 pm, Asinox wrote: > Hi guys, well.. i dont know what this mean : > > '_CheckLogin' object has no attribute 'objects' > > any idea? > thanks > > in my views.py > > from django.shortcuts import render_to_response, get_object_or_404, > Http404 > from django.conf.urls.defaults import * > from django.template import RequestContext > from django.contrib.auth import authenticate, login, logout > from django.contrib.auth.decorators import login_required > > @login_required > #listar todas las patas > def Dpatas(request): > data = Dpata.objects.filter() > return render_to_response('account/dpatas.html',{'registros': > data},context_instance = RequestContext(request)) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: customization using form_class with generic views
Assuming that you set_sub_date() function just sets the publish date to when the item was created and easy way to do this is in the model class PressRelease(models.Model): pub_date = models.DateField(auto_now_add=True) That will just set the pub_date to the current date when it is added to the DB. Not sure if this was the functionality you were looking for. Cheers, Dan On Jul 25, 8:58 pm, djangonoob wrote: > I would like to use Django's generic views for create, update, delete > operations. However, i am start with the first step: > the create operation. > > What i want to do is to use the > django.views.generic.create_update.create_object function, using the > form_class as the required arguments. I would like to to set the > pub_date ( found in models.py ) as datetime.datetime.now() via > customizing the model's form.is_valid > > I understand that i can set the pub_date as datetime.datetime.now() > right in the models.py, but i would want to learn > how to customize it using forms. > > How do i link the django.views.generic.create_update.create_object > function thing to the set_pub_date function in views.py > so that i can customize the input before saving? > > Or, is there any other way i can use the form_class ( with generic > views ) so that i can customize the model's form before saving? > > Wth the current code found here ( and also the link to dpaste ) , i > received the following error: > 'ModelFormOptions' object has no attribute 'many_to_many' > > How do i link the django.views.generic.create_update.create_object > function thing to the set_pub_date function in views.py > so that i can customize the input before saving? > > Or, is there any other way i can use the form_class ( with generic > views ) so that i can customize the model's form before saving? > > The following is my code: ( a link to django paste is > here:http://dpaste.com/71445/ ) > > #urls.py > press_detail_dict = { > 'queryset': PressRelease.objects.all(), > 'template_name':'press/detail.html', > 'template_object_name':'press', > > } > > press_list_dict = { > 'queryset': PressRelease.objects.all(), > 'template_name':'press/press_list.html', > 'allow_empty':False, > 'template_object_name':'press', > > } > > press_create_dict = { > # just a side note: on the template : press_create.html, call the form > just by using {{ form }} > 'form_class': PressReleaseCRUD, > 'template_name':'press/press_create.html', > 'post_save_redirect':'/press/list/', > #'extra_context':{'pub_date': set_pub_date()} > // the above line is commented out bcos is causes an error : > TypeError: set_pub_date() takes exactly 1 argument (0 given) > > } > > urlpatterns = patterns('', > (r'^detail/(?P\d+)/$','press.views.detail'), > > #using generic views -> list/detail generic views > (r'^list/$', 'django.views.generic.list_detail.object_list', > press_list_dict), > (r'^detail/(?P\d+)/$', > 'django.views.generic.list_detail.object_list', press_detail_dict), > > # testing django.views.generic.create_update.create_object > (r'^create/$', 'django.views.generic.create_update.create_object', > press_create_dict), > > #using generic views redirect > #(r'$','django.views.generic.simple.redirect_to',{'url':'/press/ > list/'}) > > ) > > # views.py > class PressRelease(models.Model): > title = models.CharField(max_length=100) > body = models.TextField() > pub_date = models.DateField() > author = models.CharField(max_length=100) > > def __unicode__(self): > return self.title > > class PressReleaseCRUD(ModelForm): > class meta: > model = PressRelease > exclude = ['pub_date'] > > # press_create.html > > {{ form.as_p }} > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble getting page to work
what error are you getting? On Aug 1, 4:41 pm, cprsystems wrote: > I'm trying to write a simple html page using Django that passes one > variable via a submit button and text line and prints it out to > another hmtl document. I'm having trouble getting it to work. Could > someone explain what I'm doing wrong? I've included the code below. > > urls.py > # -*- coding: cp1252 -*- > from django.conf.urls.defaults import * > from dantest.views import * > > # Uncomment the next two lines to enable the admin: > # from django.contrib import admin > # admin.autodiscover() > > urlpatterns = patterns('', > ('^htmlp1/$', htmlp1), > ('^htmlp2/$', htmlp2), > ) > > views.py > from django.shortcuts import render_to_response > import datetime > > def htmlp1(request): > now = datetime.datetime.now() > return render_to_response('page-one.html', locals()) > > def htmlp2(request): > student_id = request.GET['student_id'] > # if id is 12345 then > # if id is 54321 > return render_to_response('page-two.html', locals()) > > page-one.html > > > > Please enter your student ID, you hopeless waste of a dorm room > > > > > > > To show how to use variables in the template, the time is {{now}} > > > > page-two.html > > > You entered id {{student_id}} > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Threaded comments on django 1.1
Have you checked out: http://code.google.com/p/django-threadedcomments/ I think it is still being updated for 1.1, but it should still work with 1.1. I haven't used it, just know of it's existence. Cheers, Dan On Aug 7, 11:44 am, Alessandro Ronchi wrote: > I must add threaded comments to my django 1.1 app. > Is there anything already done I can use? > > Any advise? > > -- > Alessandro Ronchi > > SOASI > Sviluppo Software e Sistemi Open Sourcehttp://www.soasi.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-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to deploy Django on the web server?
I just wanted to give a shout out as well to webfaction. I used to use my own virtual private server for hosting django stuff, but to cut costs i switched to a webfaction account and it is pretty fantastic. Super easy to set up, if you decide to go that way just drop me and email and i'd be happy to help you get set up and running. Cheers, Dan On Aug 7, 3:34 pm, lzantal wrote: > On Aug 7, 12:06 pm, justin jools wrote:> This > has been driving me nuts for a month. > > > I wanted to use a free web server to do development testing and have > > found : 000webhost.com and heliohost.com which apparently support > > Python, but what about Django? Do I install that myself? > > > I have read the django book on deployment chapter but find it doesnt > > tell me what I want. > > > Could someone please just tell me simply how I can get my scripts > > running on the webserver. > > Tryhttp://webfaction.com. > They have super easy install for django through their control panel > > hope that helps > > lzantalhttp://twitter.com/lzantal > > > > > justinjo...@googlemail.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-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Authenication for django.views.generic Views
http://docs.djangoproject.com/en/dev/topics/auth/#limiting-access-to-generic-views hope this helps. Basically you write your own view which calls the generic view after you have done your authentication. On Apr 16, 11:25 am, Col Wilson wrote: > I'm using generic views to render my pages > (django.views.generic.date_based, django.views.generic.list_detail > etc) and they're very handy. > > However, the app I'm trying to build would like a security and on > reading the "User Authentication in Django" document, it just talks > about adding authentication to the views. > > Generic views of course are buried in the django installation > directories and you don't want to go messing about in there, so it's > not obvious to me how I can do that. > > Can someone give me a hand please? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Multiple Django versions on one server?
virtualenv can be used with mod_wsgi, we are doing so on our production servers. see http://code.google.com/p/modwsgi/wiki/VirtualEnvironments for more information Cheers, Dan On May 3, 8:26 am, Stodge wrote: > I am aware of virtualenv, but can it be used with mod_wsgi. Time to do > some reading. I have minimal control of the target cluster - I don't > know yet if I'm allowed to have a user account; I doubt it. I think I > hand off an RPM to the maintainers and they install it for me. Though > the RPM is allowed to run Python scripts. > > Thanks > > On May 3, 8:10 am, Daniel Roseman wrote: > > > > > > > On May 3, 1:03 pm, Stodge wrote: > > > > We're about to deploy our Django app on our production Redhat cluster > > > using mod_wsgi, earlier than expected. We developed the app using > > > Django 1.2b1 because we wanted the multiple database support. > > > Unfortunately, the cluster uses Django 1.1.x. What are the options for > > > running two versions on Django on the same machine? I could probably > > > revert several changes to our app to support Django 1.1.x, but that is > > > the least attractive option, simply because we're using more than one > > > database. Is there any way to place a copy of the Django beta into > > > myapp/django and use that instead of the installation in site- > > > packages? Thanks > > > This is what virtualenv is for. > > -- > > 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 > > > athttp://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Need subset on Admin interface
Just trying to clarify your question a bit... Are you asking if there is a way in the admin interface that when a user selects a switch from a drop down box that the port drop down box will be automatically populated/filtered based on the selection in the switch drop down? If this is the case I don't believe that it is currently possible "out of the box" in the Django admin. Some work was being done to integrate JQuery into the admin for some Ajaxy stuff, but at the moment I don't think that very much found it's way in. There are probably a few 3rd party projects that implement this, but I don't know of any off the top of my head. If you already know what switch a user as selected (i.e. they saved it previously), then you can probaby populate the port list by overriding the formfield_for_foreign_key method in the AdminModel (see: http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#modeladmin-methods) Hope this helps! Dan Harris dih0...@gmail.com On Jun 8, 10:04 am, onorua wrote: > I have > > class User(models.Model): > Switch = models.ForeignKey(Switch, related_name='SwitchUsers') > Port = models.ForeignKey(Port) > > class Switch(models.Model): > Name = models.CharField(max_length=50) > > class Port(models.Model): > PortNum = models.PositiveIntegerField() > Switch = models.ForeignKey(Switch, related_name = "Ports") > > > I need when I create User or change User, and choose some Switch to > have Ports only related to that Switch in Option Box. > > How can I acheave it? > Thank you. -- 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: setting DEBUG=False disables flatpages
You need to have a 500.html and a 404.html defined when DEBUG=False. See: http://code.djangoproject.com/ticket/3335 Hope this helps! Dan Harris dih0...@gmail.com On Jun 8, 2:56 pm, adrian wrote: > tracked the problem more down... > > the problem appeared when using own handler404/handler500 views and > returning the invalid HttpResponse instead of HttpResponseNotFound/ > HttpResponseServerError. This is not documented and needs doc > improvement ... -- 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 subset on Admin interface
Actually when I say not possible out of the box, I should really say without having to write some custom code. Since JQuery is built in, you should be able to write your own JQuery function that gets called when the switch drown down is changed (see: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-media-definitions). This function should make an ajax call to a custom view in your model admin (see: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-views-to-admin-sites). Overall you will have to write a javascript function (JQuery) and a custom view for your ModelAdmin. You of course don't have to use JQuery, but it is included by default in the admin and is quite popular. Dan Harris dih0...@gmail.com On Jun 8, 3:17 pm, onorua wrote: > Hello, thank you for your reply! > That's really what I've looked for, some way to prepopulate one drop- > box according to selected another one. > Crappy that it's impossible to do out of the box (would be great if it > could do). > > Thank you for the hints about JQuery and 3rd party application, I'll > give it a try. > > On 8 июн, 22:03, Dan Harris wrote: > > > > > Just trying to clarify your question a bit... > > > Are you asking if there is a way in the admin interface that when a > > user selects a switch from a drop down box that the port drop down box > > will be automatically populated/filtered based on the selection in the > > switch drop down? > > > If this is the case I don't believe that it is currently possible "out > > of the box" in the Django admin. Some work was being done to integrate > > JQuery into the admin for some Ajaxy stuff, but at the moment I don't > > think that very much found it's way in. There are probably a few 3rd > > party projects that implement this, but I don't know of any off the > > top of my head. > > > If you already know what switch a user as selected (i.e. they saved it > > previously), then you can probaby populate the port list by overriding > > the formfield_for_foreign_key method in the AdminModel > > (see:http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#modeladmin-me...) > > > Hope this helps! > > > Dan Harris > > dih0...@gmail.com > > > On Jun 8, 10:04 am, onorua wrote: > > > > I have > > > > > > class User(models.Model): > > > Switch = models.ForeignKey(Switch, related_name='SwitchUsers') > > > Port = models.ForeignKey(Port) > > > > class Switch(models.Model): > > > Name = models.CharField(max_length=50) > > > > class Port(models.Model): > > > PortNum = models.PositiveIntegerField() > > > Switch = models.ForeignKey(Switch, related_name = "Ports") > > > > > > > I need when I create User or change User, and choose some Switch to > > > have Ports only related to that Switch in Option Box. > > > > How can I acheave it? > > > Thank you. -- 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: Model inheritance and simple access
Not sure if this will work as I don't usually do much with model inheritance but according to docs at: http://docs.djangoproject.com/en/dev/topics/db/models/#id7 this might work (not pretty, but somewhat minimal code)... p = Parent1.objects.get(id=1) try: p.childa.basemthod() except: try: p.childb.basemethod() except: raise Execption("not ChildA or ChildB") Django adds in the lower cased name of the class as a property when you query the super class and throws an exception if you access a property that isn't there. So something like the above "might" work. And obviously if you have like 5 child classes, this gets ugly very quickly. Dan Harris dih0...@gmail.com On Jun 8, 3:27 pm, John M wrote: > Hmm, that doesn't really get me what I want, it just caches the > related child objects in one SQL query. > > What I want is a single interface and have django figure out what type > of child object I have (like multiple inheritance but 'better'). > > So in my example: > > p = Parent1.objects.get(id=1) > p.child.basemethod() > > django would know what p.child is (either ChildA or ChildB) and I > wouldn't need to know. > > Is that available? > > J > > On Jun 8, 11:09 am, Dejan Noveski wrote: > > > > >http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4 > > > select_related() > > > On Tue, Jun 8, 2010 at 8:05 PM, John M wrote: > > > I've gotten model inheritance working just fine, but was hoping > > > someone could confirm the best way to access the model. > > > > When I have a Base model which has a ForeignKey to a parent table, and > > > that base model has inherited models after it, how can I refer to only > > > one name when referencing the parent model. > > > > As an example: > > > > class Base(models.Model): > > > parent = models.ForeignKey(Model1) > > > > class Meta: > > > abstract = True > > > > def basemethod(): > > > print "hello" > > > > class ChildA(Base): > > > pass > > > > class ChildB(Base): > > > pass > > > > p1 = Model1() > > > p1.save > > > x = ChildA() > > > x.parent = P1 > > > x.save() > > > > p2 = Model1() > > > p2.save() > > > y = ChildB() > > > y.parent = P1 > > > y.save() > > > > Now, I want to access the children from the parent, but I don't want > > > to have to know what base class they are, is there a way to do that? > > > Right now I'm using a property which figures it out based on some > > > other fields, but would love to be able to say > > > > p = Parent1.objects.get(id=1) > > > p.child.basemethod() > > > > Is this possible? > > > > Thanks > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Django users" group. > > > To post to this group, send email to django-us...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com > > groups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/django-users?hl=en. > > > -- > > -- > > Dejan Noveski > > Web Developer > > dr.m...@gmail.com > > Twitter:http://twitter.com/dekomote|LinkedIn:http://mk.linkedin.com/in/dejannoveski -- 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: i can't import newforms(newbie)
Hey there, newforms was renamed to forms for the Django 1.0 release, this is the reason why the statement "from django import newforms as forms" doesn't work (because newforms does not exist anymore). Anywhere you see newforms you can probably replace with forms. What tutorials are you reading? If they are the official Django tutorials that is most likely a bug in the documentation. The documentation on the deprecation of newforms in favor of form is in the Django 1.0 release notes at: http://docs.djangoproject.com/en/dev/releases/1.0/ Cheers, Dan Harris dih0...@gmail.com On Jun 8, 3:46 pm, refreegrata wrote: > hello list > i'm a newbie with django trying to learn > Now i have a question > when i do > --- > from django import newforms as forms > > django throw an exception : "Error was: cannot import name newforms" > > But when i do > --- > from django import forms > --- > all works fine > > Mi question is, in all tutorial that i read, the writter say something > like "the recommended way to import is 'from django import newforms as > forms'". > > Why this way don't work now?.In the last version of Django newforms > was replaced for form?. I can't find nothing in the official > documention. > > Mi PC have Django 1.2.1(the latest stable version) > > That's my question. Thank's all. And sorry for my poor english, the > english isn't my mother language. -- 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's default id (auto primary key) sorting
Hey RJ, I'm not seeing the problem you're having. If i have a model like this: class MyModel(models.Model): field = models.CharField(max_length=100) class Meta: ordering = ['id'] # Ascending by id #ordering = ['-id'] # Descending by id This works just fine for me. Flipflop the comments to toggle ascending vs descending. Hope this helps, Dan Harris dih0...@gmail.com On Jun 5, 9:16 pm, rahul jain wrote: > Hi Django, > > I tried lots of different ways to get my ids listed in ascending order > (1 - x). But it always displays id's (x -1). > > This is what I tried > > So, I am talking about auto increment id which is generated by default > by Django. > > on models admin > ordering = ('-id',) > > also i tried > > on class meta > > order_by = ('-id',) > > This is only happening with auto-increment primary key i.e id. Not > with others. Manually I can set it by going to admin > and then sorting. But I need to set the default ascending order > sorting for id's. > > Is it a bug or something I am missing. > > --RJ -- 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: assigning data based on a comparison between two tables
Perhaps not the greatest way of doing things, but simple to code/read: class Candidate(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) incumbent = models.BooleanField() class HoldsOffice(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) for officer in HoldsOffice.objects.all(): candidates = Candidate.objects.filter(first_name__iequals=officer.first_name).filter(last_name__iequals=officer.last_name) if len(candidates)>0: raise Exception("More than 1 match found") candidates[0].incumbent = True candidates[0].save() Something like that might work for you assuming that the models and stuff are similar. Also, this code is just off the top of my head, so who knows if it will actually work :) Cheers, Dan Harris dih0...@gmail.com On Jun 8, 6:30 pm, Nick wrote: > I have two models. One is a list of candidates that have filed to run > for office. The second is a list of people who currently hold > office. > > I'd like to compare the two tables and whenever a match is found > between the two (an entry in the candidate table shares the same > last_name and first_name with an office holder from the holds office > table) I'd like to check off a box in the Candidate table called > 'incumbent'. > > how would I begin to do this. They both have columns called last_name > and first_name that I can use to compare but I don't know the syntax. -- 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 subset on Admin interface
Sounds about right, glad it's working for you! Dan Harris dih0...@gmail.com On Jun 10, 12:41 pm, onorua wrote: > I did following: > add Media JS for User model (jquery and my own script follows), with > FireBug get the names of HTML id of the elemets I want to process. > Then created view with JSON output. > > $(document).ready(function() { > $('#id_Port').html(""); > $('#id_Switch').change(function() { > var switch_id = $('#id_Switch').val(); > var ports = [] > $.post("/cmdb/switch_ports/"+switch_id+"/", { "func": > "getNameAndTime" }, > function(data){ > for ( var i = 0; i < data.length; i++) { > var onePort = " +"\">"+data[i].fields.PortNum+""; > $('#id_Port').append(onePort) > } > }, "json"); > }); > > }) > > On 8 июн, 22:22, Dan Harris wrote: > > > > > Actually when I say not possible out of the box, I should really say > > without having to write some custom code. Since JQuery is built in, > > you should be able to write your own JQuery function that gets called > > when the switch drown down is changed > > (see:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-me...). > > This function should make an ajax call to a custom view in your model > > admin > > (see:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-views-...). > > > Overall you will have to write a javascript function (JQuery) and a > > custom view for your ModelAdmin. You of course don't have to use > > JQuery, but it is included by default in the admin and is quite > > popular. > > > Dan Harris > > dih0...@gmail.com > > > On Jun 8, 3:17 pm, onorua wrote: > > > > Hello, thank you for your reply! > > > That's really what I've looked for, some way to prepopulate one drop- > > > box according to selected another one. > > > Crappy that it's impossible to do out of the box (would be great if it > > > could do). > > > > Thank you for the hints about JQuery and 3rd party application, I'll > > > give it a try. > > > > On 8 июн, 22:03, Dan Harris wrote: > > > > > Just trying to clarify your question a bit... > > > > > Are you asking if there is a way in the admin interface that when a > > > > user selects a switch from a drop down box that the port drop down box > > > > will be automatically populated/filtered based on the selection in the > > > > switch drop down? > > > > > If this is the case I don't believe that it is currently possible "out > > > > of the box" in the Django admin. Some work was being done to integrate > > > > JQuery into the admin for some Ajaxy stuff, but at the moment I don't > > > > think that very much found it's way in. There are probably a few 3rd > > > > party projects that implement this, but I don't know of any off the > > > > top of my head. > > > > > If you already know what switch a user as selected (i.e. they saved it > > > > previously), then you can probaby populate the port list by overriding > > > > the formfield_for_foreign_key method in the AdminModel > > > > (see:http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#modeladmin-me...) > > > > > Hope this helps! > > > > > Dan Harris > > > > dih0...@gmail.com > > > > > On Jun 8, 10:04 am, onorua wrote: > > > > > > I have > > > > > > > > > > class User(models.Model): > > > > > Switch = models.ForeignKey(Switch, related_name='SwitchUsers') > > > > > Port = models.ForeignKey(Port) > > > > > > class Switch(models.Model): > > > > > Name = models.CharField(max_length=50) > > > > > > class Port(models.Model): > > > > > PortNum = models.PositiveIntegerField() > > > > > Switch = models.ForeignKey(Switch, related_name = "Ports") > > > > > > > > > > > I need when I create User or change User, and choose some Switch to > > > > > have Ports only related to that Switch in Option Box. > > > > > > How can I acheave it? > > > > > Thank you. -- 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: error: unsupported operand type(s) for *: 'Decimal' and 'float'
The error looks like you are attempting to multiply a decimal by a float which isn't allowed. Django coerces form fields like DecimalField into a decimal object. See: http://docs.python.org/library/decimal.html for more information about the decimal object. An error occurs like the one you have if you do something like: >>> from decimal import Decimal >>> import math >>> d = Decimal("2") >>> d*math.pi Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for *: 'Decimal' and 'float' You can convert the decimal returned by the form into a float, or convert the floats into decimals and do your math. Converting to decimal is probably more precise. Hope this helps, Dan Harris dih0...@gmail.com On Jun 10, 3:22 pm, Waleria wrote: > Hello.. > > I again.now my problem is: > > I have the function following:http://paste.pocoo.org/show/224041/ > > These values i get of a form...however returns me an errorfallows > below the error > > Exception Type: TypeError > Exception Value: unsupported operand type(s) for *: 'Decimal' and > 'float' > > Exception Location: C:\simuladores\..\simuladores\detector\views.py in > graph, line 32 -- 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: select_related() depth when specifying fields
According to the select_related() documentation at: http://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.QuerySet.select_related it looks like select related "follows foreign keys as far as possible". In the documentation example it shows select_related following a foreign keys with a depth of two. Hope this helps, Dan Harris dih0...@gmail.com On Jun 10, 3:19 pm, Michael Hrivnak wrote: > If I use select_related() on a queryset and specify some attribute names, will > it follow those relationships as far as possible, or does that imply > "depth=1"? > > Thanks, > Michael > > signature.asc > < 1KViewDownload -- 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: annotate with query set for distinct values
The problem is the GROUP BY you are looking to get. The problem with doing a group by you don't get the whole object which is what the Django queryset is trying to return: res = queryset.annotate(Count("name")) This will give you a result set that you want and you can iterate over like: {% for r in res %} {{ r.name }} - {{ r.name__count}} {% endfor %} however there may be duplicated {{ r.name }} Dan Harris dih0...@gmail.com On Jun 10, 5:24 pm, SlafS wrote: > Thanks. > > I've already tried that but this isn't quite what i'm looking for. As > u wrote this returns a list, but I would like to obtain my calculated > property when I'm iterating over this. Like so (let's say the result > is in res variable) : > > {% for r in res %} > {{r.xxx}} - {{r.name__count}} > {% endfor %} > > I'm starting to think that there's no such nice way to acheive that :/ > > On 10 Cze, 23:06, Dan Harris wrote: > > > > > Here is an example: > > > # In models.py > > class TestModel(models.Model): > > name = models.CharField() > > > # Get a listing of unique names and their counts > > # In some view > > from django.db.models import Count > > > TestModel.objects.values("name").annotate(Count("name")) > > > This will return a list of the form: > > > [{'name__count': 2, 'name': u''}, {'name__count': 1, 'name': > > u'bbb'}] > > > Hope this helps! > > > Dan Harris > > dih0...@gmail.com > > > On Jun 10, 5:01 pm, SlafS wrote: > > > > Hi there! > > > I have a question. If i have a model with some fields (let's say all > > > CharFields named aaa,bbb,ccc etc. and some calculated properties named > > > xxx and zzz) how can I obtain something similar to > > > > "SELECT aaa, count(aaa) FROM my_model_table GROUP BY aaa;" > > > i.e. a list of - lazy loaded - objects with distinct aaa values and an > > > extra column which indicates how many entries of a specific aaa are in > > > the table. > > > > I would like to acheive that with QuerySet and annotate so that I can > > > get a list of objects to use their other properties (xxx or zzz) e.g. > > > in my template > > > > Regards -- 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: annotate with query set for distinct values
Here is an example: # In models.py class TestModel(models.Model): name = models.CharField() # Get a listing of unique names and their counts # In some view from django.db.models import Count TestModel.objects.values("name").annotate(Count("name")) This will return a list of the form: [{'name__count': 2, 'name': u''}, {'name__count': 1, 'name': u'bbb'}] Hope this helps! Dan Harris dih0...@gmail.com On Jun 10, 5:01 pm, SlafS wrote: > Hi there! > I have a question. If i have a model with some fields (let's say all > CharFields named aaa,bbb,ccc etc. and some calculated properties named > xxx and zzz) how can I obtain something similar to > > "SELECT aaa, count(aaa) FROM my_model_table GROUP BY aaa;" > i.e. a list of - lazy loaded - objects with distinct aaa values and an > extra column which indicates how many entries of a specific aaa are in > the table. > > I would like to acheive that with QuerySet and annotate so that I can > get a list of objects to use their other properties (xxx or zzz) e.g. > in my template > > Regards -- 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: select_related() depth when specifying fields
Michael, I believe the case of query.select_related(person__place) will "only" follow the place foreign key. This means that if you had 5 FK's in your person models, that only a single FK would be followed instead of all 5 for optimization. Upon further looking there is also a "depth" argument you can pass to select related to specify how far you want it to go. For example: query.select_related(depth=5) # This will follow all FK's 5 levels deep query.select_ralted('person__place', depth=5) # This will follow only the place FK 5 levels deep That is how I read the docs, it may not be correct :) Cheers, Dan Harris dih0...@gmail.com On Jun 10, 4:54 pm, Michael Hrivnak wrote: > I read that myself. I asked the question because it goes on to state that you > can specify down-stream models like this: > > query.select_related(person__place) > > If it follows all relationships as far as possible, even when specific > relationships are requested, why would that syntax ever be necessary? We > could just specify "people", and it would follow the "place" relationship > automatically. Is it only to specifically prevent it from following other > relationships on the "person" model? > > The docs seem to be ambiguous on this point. > > Thanks, > Michael > > On Thursday 10 June 2010 03:37:59 pm Dan Harris wrote: > > > > > According to the select_related() documentation at: > >http://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db > > .QuerySet.select_related > > > it looks like select related "follows foreign keys as far as > > possible". In the documentation example it shows select_related > > following a foreign keys with a depth of two. > > > Hope this helps, > > > Dan Harris > > dih0...@gmail.com > > > On Jun 10, 3:19 pm, Michael Hrivnak wrote: > > > If I use select_related() on a queryset and specify some attribute names, > > > will it follow those relationships as far as possible, or does that imply > > > "depth=1"? > > > > Thanks, > > > Michael > > > > signature.asc > > > < 1KViewDownload > > > > signature.asc > < 1KViewDownload -- 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: error: unsupported operand type(s) for *: 'Decimal' and 'float'
To be more specific it looks like this: ((pow(2*math.pi*v,2)))*((pow(2,2)) piece of your very large single line of calculation is the culprit. You should be able to convert to a decimal like so: {previous_stuff_here} * Decimal(str(((pow(2*math.pi*v, 2)))*((pow(2,2 * {more_stuff_here } As a readability thing, you might want to split that giant line of code into a few separate calculations, but that's just an idea! Cheers, Dan Harris dih0...@gmail.com On Jun 10, 3:33 pm, Dan Harris wrote: > The error looks like you are attempting to multiply a decimal by a > float which isn't allowed. Django coerces form fields like > DecimalField into a decimal object. > See:http://docs.python.org/library/decimal.html > for more information about the decimal object. > > An error occurs like the one you have if you do something like: > > >>> from decimal import Decimal > >>> import math > >>> d = Decimal("2") > >>> d*math.pi > > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for *: 'Decimal' and 'float' > > You can convert the decimal returned by the form into a float, or > convert the floats into decimals and do your math. Converting to > decimal is probably more precise. > > Hope this helps, > > Dan Harris > dih0...@gmail.com > > On Jun 10, 3:22 pm, Waleria wrote: > > > > > Hello.. > > > I again.now my problem is: > > > I have the function following:http://paste.pocoo.org/show/224041/ > > > These values i get of a form...however returns me an errorfallows > > below the error > > > Exception Type: TypeError > > Exception Value: unsupported operand type(s) for *: 'Decimal' and > > 'float' > > > Exception Location: C:\simuladores\..\simuladores\detector\views.py in > > graph, line 32 -- 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: Writing your first Django app tutorial, part 3 question
According to your urlconf you should be going to a url like http://127.0.0.1/polls/5/results where the "5" is the ID of the poll you are looking at the results for. You are just missing the ID it looks like. See this: http://docs.djangoproject.com/en/1.2/intro/tutorial03/#write-your-first-view part of the documentation for more. Cheers, Dan Harris dih0...@gmail.com On Jun 10, 6:30 pm, albert kao wrote: > I try the "Writing your first Django app tutorial, part 3" (http:// > docs.djangoproject.com/en/dev/intro/tutorial03/#intro-tutorial03) with > Django-1.2.1. > I have got a Page not found (404) when modifying the urls.py described > in the "Decoupling the URLconfs" section: > Request Method: GET > Request URL: http://127.0.0.1:8000/polls/results > > mysite/urls.py is: > from django.conf.urls.defaults import * > > # Uncomment the next two lines to enable the admin: > from django.contrib import admin > admin.autodiscover() > > urlpatterns = patterns('', > (r'^polls/', include('mysite.polls.urls')), > (r'^admin/', include(admin.site.urls)), > ) > > mysite/polls/urls.py is: > from django.conf.urls.defaults import * > > # Uncomment the next two lines to enable the admin: > from django.contrib import admin > admin.autodiscover() > > urlpatterns = patterns('mysite.polls.views', > (r'^$', 'index'), > (r'^(?P\d+)/$', 'detail'), > (r'^(?P\d+)/results/$', 'results'), > (r'^(?P\d+)/vote/$', 'vote'), > ) -- 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: not able to recognize non-default python files in app + project directory
When you split things out into multiple files or directories you have to remember to import them into the models.py file or the __init__.py file (if using a directory). So if i had some models in a new file "extraModels.py" for example # In extraModels.py class ExtraModel(models.Model): pass Then in the regular "models.py" # In models.py from extraModels import ExtraModel class RegularModels(model.Model): pass The key is that you ahve to import any models in your split files into your normal models.py file. This is because Django looks for models in the models.py file only. If you make a models directory, you have to import all models you want Django to recognize into your __init__.py file within the models directory. Hopefully this makes sense, if not I can try to be more clear. Dan Harris dih0...@gmail.com On Jun 10, 4:46 pm, rahul jain wrote: > anyone on this ?? > > --RJ > > > > On Thu, Jun 10, 2010 at 11:34 AM, rahul jain wrote: > > Hi Django, > > > In my app directory, I splitted my models and views.py into multiple > > files since they start becoming very long but django is not able to > > recognize those files . > > It only recognizes models.py, views.py, tests.py (default ones). > > > So In my other files If i do this > > > from ..models import > > > I get this error > > > ImportError: cannot import name > > > If I do the same on views.py, it just works fine. > > > Even on Eclipse I can see Django default files with different symbol > > and python files with different symbols. > > > How to solve this problem ? > > > --RJ -- 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: Writing your first Django app tutorial, part 3 question
Looks like you haven't created any polls yet, at least not one with an ID of 5. Go into the admin section described in part 2 of the tutorial and make a few polls. Once you've create some you should see polls of IDs 1,2,3 etc show up and the URLs should start to work. Dan Harris dih0...@gmail.com On Jun 10, 10:09 pm, albert kao wrote: > On Jun 10, 6:30 pm, albert kao wrote: > > > > > > > I try the "Writing your first Django app tutorial, part 3" (http:// > > docs.djangoproject.com/en/dev/intro/tutorial03/#intro-tutorial03) with > > Django-1.2.1. > > I have got a Page not found (404) when modifying the urls.py described > > in the "Decoupling the URLconfs" section: > > Request Method: GET > > Request URL: http://127.0.0.1:8000/polls/results > > > mysite/urls.py is: > > from django.conf.urls.defaults import * > > > # Uncomment the next two lines to enable the admin: > > from django.contrib import admin > > admin.autodiscover() > > > urlpatterns = patterns('', > > (r'^polls/', include('mysite.polls.urls')), > > (r'^admin/', include(admin.site.urls)), > > ) > > > mysite/polls/urls.py is: > > from django.conf.urls.defaults import * > > > # Uncomment the next two lines to enable the admin: > > from django.contrib import admin > > admin.autodiscover() > > > urlpatterns = patterns('mysite.polls.views', > > (r'^$', 'index'), > > (r'^(?P\d+)/$', 'detail'), > > (r'^(?P\d+)/results/$', 'results'), > > (r'^(?P\d+)/vote/$', 'vote'), > > ) > > http://localhost:8000/polls/5/display the following error: > Page not found (404) > Request Method: GET > Request URL: http://localhost:8000/polls/5/ > > No Poll matches the given query. > You're seeing this error because you have DEBUG = True in your Django > settings file. Change that to False, and Django will display a > standard 404 page. -- 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: error: unsupported operand type(s) for *: 'Decimal' and 'float'
That looks ok from a code readability point of view, however you will still need to cast the form values to float or cast the float values (i.e. pow(2,2) and pow(2*math.pi*v,2) to Decimals otherwise will you will get an UnsupportedOperation exception. Dan Harris dih0...@gmail.com On Jun 11, 6:58 am, Waleria wrote: > Dan, > > Do you speak for me to do this? for the example... > > http://paste.pocoo.org/show/224233 > > On 10 jun, 16:51, felix wrote: > > > > > use > > > float( form.cleaned_data['a'] ) > > > etc > > > also, when retreiving the field from the db it will be a Decimal > > object and needs to be converted to do math with it > > > on_sale = float(myObj.price) * 0.9 > > > On Jun 10, 9:22 pm, Waleria wrote: > > > > Hello.. > > > > I again.now my problem is: > > > > I have the function following:http://paste.pocoo.org/show/224041/ > > > > These values i get of a form...however returns me an errorfallows > > > below the error > > > > Exception Type: TypeError > > > Exception Value: unsupported operand type(s) for *: 'Decimal' and > > > 'float' > > > > Exception Location: C:\simuladores\..\simuladores\detector\views.py in > > > graph, line 32 -- 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: Model named FOOD_DES shows as "foo d_des" in admin
I'm not sure why you are seeing the space in the admin, but here's a bit of info regarding changing what is displayed: You can change a meta option on your model to set what the name will be displayed as in the admin like so: class MyModel(models.Model): field = models.CharField(max_length=100) class Meta: verbose_name = "Product" # Your name here verbose_name_plural = "Products" # Your pluralized name here Also, if you do not want to name your model as the same name as the legacy table, you can specify which database table the models uses with the "db_table" meta option. Please refer to the docs at: http://docs.djangoproject.com/en/1.2/ref/models/options/#model-meta-options for more information. Cheers, Dan Harris dih0...@gmail.com On Jun 11, 1:06 pm, creecode wrote: > Hello all, > > I have a model named FOOD_DES (the name if from an existing schema > that I'm trying to mirror). When I view it in the admin it's name is > shown as "foo d_des", notice the space. > > Any thoughts on why/where the space is added and how I can get rid of > it? > > I'm wondering if this something to do with FOO being a computer > programming placeholder name? > > Toodle-loo > creecode -- 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: Model named FOOD_DES shows as "foo d_des" in admin
If verbose_name isn't provided the docs say that "Django will use a munged version of the class name: CamelCase becomes camel case." This might explain your problem, it looks at FOOD_DES and assumes that the first F and first O are camel cased words and splits them into two words, hence the space. See: http://docs.djangoproject.com/en/1.2/ref/models/options/#verbose-name for more details. Cheers, Dan Harris dih0...@gmail.com On Jun 11, 2:38 pm, creecode wrote: > Hello Dan, > > Thanks for the info. verbose_name does take care of the display > problem and I may end up using that option for a more user friendly > experience. > > @ALL: I would like to understand where the space is being added. I > have looked around a bit in the source for Django but I haven't seen > anything that pops out. Perhaps this is happening in Python? > Pointers appreciated. > > On Jun 11, 11:22 am, Dan Harris wrote: > > > You can change a meta option... > > Toodle-loo > creecode -- 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: Simplification of a DB "query"
This is totally off the top of my head and may not compile or work :) But something like this might be what you're looking for: # Example Model class MyModel(models.Model): start_time = models.TimeField() # Example query from django.db.models import Q from django.db.model import Max # Get the maximum start time before the specified start time (3pm) result = MyModel.objects.filter(start_time__lt='15:00:00').aggregate(Max(start_time)) # Build two Q objects to represent the two cases we want # 1.) The last meeting before the specified time (3pm) - we got the last start time via the aggregation latest_meeting = Q(start_time=result['start_time__max']) # 2.) All meetings between 3pm and 5pm after_3_and_before_5 = Q(start_time__gte='15:00:00', start_time__lte='17:00:00') # Filter the objects by ORing the two Q objects together giving us: # "show me all objects that are the last meeting before 3 or start betweeen 3pm and 5pm" MyModel.objects.filter(latest_meeting | after_3_and_before_5) Not sure if this is what you're looking for or if it's even right :) Dan Harris dih0...@gmail.com On Jun 11, 4:28 pm, Cesar Devera wrote: > I'm not sure how to do directly in Django ORM, but if you use plain > SQL queries, you could do try: > > select * from conference_room cr1 > where cr1.start_time >= > (select max(start_time) from conference_room cr2 where cr2.start_time > < :yout_filter_time) > and cr1.start_time < :your_filter_time > > the "select max" gives you the row immediately before your time > range. > > if you don't want to use a plain SQL approach, you will have to do two > accesses to the DB. then, there are several way to do so, like: > > ConferenceRoom.objects.filter(start_time__gt=ConferenceRoom.objects.filter( > start_time__lt=your_start_time).aggregate(Max('start_time')) > [:1].get().start_time).filter(start_time__lt=your_end_time) > > sorry. I'm not sure if I typed correctly, but it's the same idea of > the SQL statement I mentioned before: > 1. find the maximum date before your the start date of your time frame > 2. find all events after that date (1) including it (greater and equal > to) and before your end date > > hope it helps, > > regards, > > - > On 10 jun, 10:56, illuminated wrote: > > > > > Hi all, > > > I'm writing a django app and need help with filtering results from DB. > > > There is a conference room and it's usage is stored in django model. > > There is a field "start_time" (model.TimeField); no "end_time". When I > > query the table with a time range (i.e. 3pm - 5pm) I would like to get > > not only events that start within given time range, but also the one > > currently running (the last one that started before 3pm). > > > The only solution I have in my mind at the moment is to have two > > queries: one would return events starting within the range, other > > would retrieve events before that, would sort them descending by time > > and I'd get just the first row. Then I'd try to join these two > > results. > > > Although the above algorithm would/should work, I was wondering if > > there was more elegant way to this? > > > Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Controlling access to objects
This article might help you out: http://djangoadvent.com/1.2/object-permissions/ Cheers, Dan Harris dih0...@gmail.com On Jun 11, 11:46 pm, Wiiboy wrote: > Hi guys, > I don't know whether the built-in permissions system would be > appropriate here, but I want to control access to objects in one of my > models, based on profile fields, like gender, age, etc. > > I planned to create a model "MyModelPermissions" like so: > class MyModelPermissions(models.Model): > mymodel = models.OneToOneField(MyModel) > gender = models.CharField(choices=[('male', 'Male'),('female', > 'Female'), ('both', 'Both')]) > > > But that doesn't seem very efficient. Any ideas on how best to do 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: ordering fields in admin form
To change the order of a foreign key in the admin and admin only, you can override the formfield_for_foreignkey method in your ModelAdmin for AtBat. See the docs at: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey for more details, but it sounds like you'll need something like this (off the top of my head, no idea if it will execute): def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_fieldname=="game": kwargs['queryset' ] = Score.objects.all().order_by('something_to_order_by_here') # replace with your ordering method return db_field.formfield(**kwargs) return super(MyModelAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) Hope this helps, Dan Harris dih0...@gmail.com On Jun 13, 8:53 am, backdoc wrote: > This only impacts the order of the records already entered. But, when > adding a new record with the admin interface, one of the fields (a > select box auto generated from line 107 below) is not in the order I > would prefer. > > While typing this email, I just figured out how to order it. I needed > to modify the ordering of the model the games column is related to (by > adding a class META). While this actually does what I want, the > downside is that it will impact this model everywhere. I would still > like to know if there's a better way do this. > > The hard part about googling this or finding it in the Django docs is > that ordering is a term that applies to so many different aspects. > > Thanks. > > On Sun, Jun 13, 2010 at 5:45 AM, Alexander Jeliuc > > > > wrote: > > You should do it in admin.py > > class MyClassAdmin(admin.ModelAdmin): > > ordering = ['-myfield'] > > > On Sun, Jun 13, 2010 at 6:18 AM, darren wrote: > > >> I'm sure the answer is probably documented clearly somewhere. But, I > >> can't find it. > > >> I would like to change the ordering of a field in a form on the admin > >> site based on the model below. The "game" column is several records > >> long. I would like to order desc. I've tried adding a META class to > >> my model and tinkering with the admin.py. But, I haven't been able to > >> figure this out. > > >> Could someone point me to the documentation? I've been reading this: > >>http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#ref-contrib-a..., > >> but I don't see what I'm looking for there. > > >> Thanks > > >> 104 class AtBat(models.Model): > >> 105 atbat_id = models.AutoField(primary_key=True) > >> 106 player = models.ForeignKey(Person, to_field='f_name', > >> verbose_name='Player', limit_choices_to={'relationship' : 'Player'}) > >> 107 game = models.ForeignKey(Score, to_field='scores_id', > >> verbose_name='Game') > >> 108 result = models.CharField('Result', choices=(('H', 'Hit'), > >> ('BB', 'Walk'), ('K', 'Strike Out'), ('ROE', 'Reached On Error'), > >> ('HBP', 'Hit By Pitch'), ('FO', 'Ground or Fly Out'), ('FC', 'Fielders > >> Choice'), ('Sacrifice', 'Sac rafice')), max_length=10) > >> 109 rbi = models.PositiveSmallIntegerField("RBI", default=0) > >> 110 > >> 111 def __unicode__(self): > >> 112 return unicode('%s %s %s %s' % (self.atbat_id, > >> self.player, self.game, self.result)) > > >> -- > >> 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, 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: modeling a book repository
Hi Tim, You can probably override the Chapter model's delete method. Inside this overridden delete method you can swap around your FK's of previous and next chapters before calling the super classes delete. Basically do your linked list management inside the delete method before the calling the super class delete. This way when the cascades go through it doesn't have links to next or previous chapters and not everything is deleted. Hope this helps, Dan Harris dih0...@gmail.com On Jun 15, 12:11 pm, Tim Arnold wrote: > Hi, > I have a model for a Book that contains Chapters. My problem is > figuring out the ordered sequence of Chapters in a Book. I first tried > setting Chapter up as a linked list with pointers to the previous > Chapter and next Chapter. That worked okay, but when I need to delete > a Chapter, the prev/next links cascade through and it wants to delete > all the chapters. > > I'm now thinking of adding a 'sequence number' to the chapter model > which I suppose will work okay, but if want to add or delete a chapter > later on, I'll have to renumber all the later chapters in the > database. > > This is a little tricky--does anyone have a better solution? > thanks, > --Tim Arnold -- 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: Question regarding subdomains of a single project
Check out this from djangosnippets: http://djangosnippets.org/snippets/1509/ It allows you to specify multiple URLconfs and then choose which you are going to use based on the domain name. This would mean that each of your subdomain gets a different URLconf which sounds like what you may be looking for. Cheers, Dan Harris dih0...@gmail.com On Jun 22, 10:59 am, Venkatraman S wrote: > On Tue, Jun 22, 2010 at 8:06 PM, M Rotch wrote: > > I'm setting up a website with multiple subdomains, and one thing I > > notice right away (and is expected) is that each subdomain has access > > to all of the URLs of the website (of course some will require logins > > still). > > hmmm. I think its the way you setup your apache? > > -V -- 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: Fields validating as optional
Jonathan, I think what you are running into is the differences between how models are declared vs how forms are declared. In models you declare the fields as blank=True and/or null=True to specify that the data stored in the database can be left blank. Something like this: class MyModel(models.Model): additional_comments = models.TextField(blank=True) When declaring a form, nothing is directly stored in the database so the keyword 'required' is used. For example: class MyForm(forms.Form): additional_comments = forms.TextField(required=False) If you are creating a form from a model, blank=True inside the models is transformed into required=False for the form. class MyModelForm(forms.ModelForm): class Meta: model = MyModel Hope this helps! Dan Harris dih0...@gmail.com On Jun 22, 4:11 pm, Jonathan Hayward wrote: > What is the preferred way to make e.g. a TextField that will pass validation > if it is left empty? I've seen two approaches apparently referenced in the > documentation: > > additional_comments = models.TextField(required = False) > > additional_comments = models.TextField(blank = True) > > and run into errors with the first. Does this mean that I should go with the > second, or is there another way that is preferred? > > I'm using 1.2. > > -- > → Jonathan Hayward, christos.jonathan.hayw...@gmail.com > → An Orthodox Christian author: theology, literature, et cetera. > → My award-winning collection is available for free reading online: > ☩ I invite you to visit my main site athttp://JonathansCorner.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.