Re: Django Country->State->City Dropdown list
Sounds like AJAX is your answer, there are lots of AJAX libraries out there that have examples on this. J On Nov 2, 10:31 am, d wrote: > URGENT! > The following is my django code. I would like to have 3 column drop- > down list. > > a member can select his location. > when a country is selected, then all states for that country will > display. the same thing happens to city. > > Now, I know it has something to do with Javascript. The question is > there is no good tutorial for that > > Please help me. It is super urgent > > If you want to show links or code, it must come with a real working > demo. I have gone thought all links found on google. > > Please direct me to the right direction. a simple step by step > instruction is very helpful > > thanks > > from django.db import models > > class Member(models.Model): > > residing_country = models.CharField(max_length=50) > residing_state = models.CharField(max_length=50) > residing_city = models.CharField(max_length=50) > > class Country(models.Model): > > country= models.CharField(max_length=20) > > class State(models.Model): > > state=models.CharField(max_length=20) > country = models.ForeignKey(Country) > > class City(models.Model): > > city=models.CharField(max_length=20) > state=models.ForeignKey(State) -- 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: Mapping models to CRUD urls?
Russ, This is GREAT stuff, thank you so much. Since I'm so new to this web stuff, and django is really the only thing I've ever used for web programming, I hadn't gotten into the GET dictionary (or parameters as I call them). Given that, I assume that the cache will look at the http://.../model3/add/ and cache that? meaning it doesn't add the parameters to the cache lookup? This actually makes my setup a little simpler, and i'll start on it soon. Thanks again for all your help. John On 7/19/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote: > > > On 7/20/07, John M <[EMAIL PROTECTED]> wrote: > > > > Does caching matter that much in my example, since it's dynamic data > > anyway? > > Don't let the fact that the data is dynamic distract you. All database > backed websites are dynamic at some level. However, when you have > thousands of requests for a resource every second, does it really > matter if the version delivered to the user is 1 second out of date? > 10 seconds? A minute? > > You should be able to serve a reasonably sized Django application > without ever having to care about caching. However, It pays to get > into a good habits early. It is a lot easier to add caching to the top > of a clean ReSTful application than it is to refactor a messy, > non-ReSTful application so that you can add caching. > > As a bonus, URL spaces that are easily cached are also the ones that > match the browsing metaphor the best (i.e., are ReSTful), so asking > the question "could I cache this" is one way of validating a design. > > 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-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it really this hard?
James, thanks for the quick reply! Ok, I like what you have there, but it doesn't solve the problem of when I want to edit an existing record, how do I use the customform? I guess I'm just missing something super simple here, no? I would think code like instance = objects.get(id=1) form = OrderForm(instance) does this get me the form filled with the data from instance? Thanks On 5/15/07, James Bennett <[EMAIL PROTECTED]> wrote: > > > On 5/15/07, John M <[EMAIL PROTECTED]> wrote: > > When I put up the form for order, I don't want the Customer (foreign > > key) to appear. I've not seen anything on the forum that shows you > > can easily eliminate a field from the form? > > In general, form_for_model and form_for_instance are for when you just > want "form for this thing" and don't care about fine-grained control > of the fields. When you do want fine-grained control of the fields, a > custom form is the way to go. > > > Unless I'm missing how to create a custom form, bind it to the DB's > > data and use it like I can form_for_instance() and form_for_model(). > > Something like this is what you're looking for, I think: > > http://dpaste.com/10396/ > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of > correct." > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it really this hard?
Ah Ha, now we're getting somewhere! Let me start searching for that, thank you!! John On 5/15/07, James Bennett <[EMAIL PROTECTED]> wrote: > > > On 5/15/07, John M <[EMAIL PROTECTED]> wrote: > > I wish the custom form option would allow me to bind to a data object, > > based on field names being the same, that way I could have fields in > > the form that aren't bound and ones that are, without a lot of hassle. > > To do that you want to get a dictionary out of the object, which means > using the '__dict__' attribute. For example: > > my_obj = MyModel.objects.get(pk=1) > form = MyForm(my_obj.__dict__) > > The form is smart enough to take a dictionary-like object and pull out > the values it wants; that's how it works with request.POST, for > example. > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of > correct." > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it really this hard?
Thank you Grigoriy, It's given me some new ideas. John On 5/16/07, Grigoriy Petukhov <[EMAIL PROTECTED]> wrote: > > > John M wrote: > > I have checked the forum, and still can't believe I can't find a > > solution to what I perceive as a simple problem: > > > > I have two models: > > > > Customer > >Name > >phone > > > > Order > >Customer (foreign key to Customer) > >date > >product > > > > When I put up the form for order, I don't want the Customer (foreign > > key) to appear. I've not seen anything on the forum that shows you > > can easily eliminate a field from the form? > > > > Unless I'm missing how to create a custom form, bind it to the DB's > > data and use it like I can form_for_instance() and form_for_model(). > > > > using FFI with a customer form, it doesn't seem to bind any data to > > the fields, unless I'm missing something big, cause that would be > > perfect, no? > > > > Hoping someone can help > > > > > > > > > > Check this thread: http://softwaremaniacs.org/forum/viewtopic.php?id=596 > Here is the solution for exactly the same problem as you have described. > Thread in russian but there is a lot of code ) > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it really this hard?
James, Thanks again so much. I think i tried the commit=False bit but it still didn't like my FK being blank for some reason. I'll have to look through the django source and double check. So, assuming my commit=false works, i should be able to say something like: form.clean_data['fk_id'] = fkobjid ? Thanks John On 5/16/07, James Bennett <[EMAIL PROTECTED]> wrote: > > > On 5/16/07, John M <[EMAIL PROTECTED]> wrote: > > Thanks for info, but what happens when the form.save() is called, > > since the FK isn't part of the clean_data, it will fail no? > > Form.save accepts a 'commit' keyword argument, which default to True; > when it's True the form will try to actually save to the database, and > when it's False it won't. So if you know that you don't yet have > enough data to correctly save to the DB, you can do: > > new_obj = form.save(commit=False) > #...do more stuff with the object before saving to the DB > > Either way, 'save()' will return the object, but passing commit=False > will tell it you're not ready to hit the DB just yet. > > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of > correct." > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it really this hard?
WOW, I hadn't seen that first one, and the second one is the 'standard' for most newforms replies, great work! Thanks again Michael. John On 5/16/07, Michael Trier <[EMAIL PROTECTED]> wrote: > > > These two posts gave me everything I needed to tackle these type of > issues: > > http://weblog.bignerdranch.com/?p=31 > > http://code.pui.ch/2007/01/07/using-djangos-newforms/ > > Michael > > On 5/16/07, James Bennett <[EMAIL PROTECTED]> wrote: > > > > On 5/16/07, John M <[EMAIL PROTECTED]> wrote: > > > Thanks for info, but what happens when the form.save() is called, > > > since the FK isn't part of the clean_data, it will fail no? > > > > Form.save accepts a 'commit' keyword argument, which default to True; > > when it's True the form will try to actually save to the database, and > > when it's False it won't. So if you know that you don't yet have > > enough data to correctly save to the DB, you can do: > > > > new_obj = form.save(commit=False) > > #...do more stuff with the object before saving to the DB > > > > Either way, 'save()' will return the object, but passing commit=False > > will tell it you're not ready to hit the DB just yet. > > > > > > -- > > "Bureaucrat Conrad, you are technically correct -- the best kind of > correct." > > > > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is it really this hard?
Wow, very cool, I didn't know that James! Again, thank you! I was trying obj.portfolio = portid and then obj.portfolio.id = portid < that was really bad according to django :-) J On 5/16/07, James Bennett <[EMAIL PROTECTED]> wrote: > > > On 5/16/07, John M <[EMAIL PROTECTED]> wrote: > > portfolio = Portfolio.objects.get(pk=portid) > > > > obj.portfolio = portfolio > > Somewhat undocumented, but you should be able to do > > obj.portfolio_id = portid > > Instead of doing the lookup and assigning the object, if you're > concerned about the extra DB hit. > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of > correct." > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: CRUD design question
Now you're talking!!! Thanks for that, it's exactly what I was thinking. Basically I am trying to make a system where you show a list of records, allow the user to view the record, edit the record or add a new one. Similar to the admin interface, but with only a view option, so in case your a 'public' user you only get view access to the data. Thanks again for the help. John On 1/4/07, Tim <[EMAIL PROTECTED]> wrote: The HTML in the template is fairly easy to do: {% if object %} we have an object so we're updating {% else %} no object so we're inserting {% endif %} I'm not quite sure how you want to handle the viewing part though. In the form HTML, just create your form as if you are doing an update: {% if form.title.errors %} {{ form.name.errors|join:", "}} {% endif %} Event Description: {{ form.title }} Enter the name of the event. * if the form title in my example contains no data, it will show up empty. If it has data, it will be filled. Pretty easy. The tougher part is in the views. > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Empty related sets = Page not found?
Thank you for the reply. On 1/10/07, Brian Beck <[EMAIL PROTECTED]> wrote: > > > Hi, > > object_list takes an allow_empty argument, try settings it to True. > >From the docs: > > allow_empty: A boolean specifying whether to display the page if no > objects are available. If this is False and no objects are available, > the view will raise a 404 instead of displaying an empty page. By > default, this is False. > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How would I do this with Djangol?
Thanks Chris,I looked at that but it only gives me one record. What i need is the last price for each stock. Maybe im using the latest() function wrong?ThanksJohn On 8/4/06, Chris Long wrote:This might help: http://www.djangoproject.com/documentation/db_api/#latest-field-name-noneChris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Tutorial missing import: Http404
obviously one needs to change: from django.http import HttpResponse, to from django.http import HttpResponse, Http404 but that's a speed-bump that should not be in the tutorial. NameError at /polls/34/ global name 'Http404' is not defined Request Method: GET Request URL: http://localhost:8000/polls/34/ Django Version: 1.8 Exception Type: NameError Exception Value: global name 'Http404' is not defined Exception Location: /home/john/Documents/code/python/django/djangostart/polls/views.py in detail, line 19 Python Executable: /usr/bin/python Python Version: 2.7.6 Python Path: ['/home/john/Documents/code/python/django/djangostart', '/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client'] Server time: Fri, 10 Apr 2015 21:30:24 + -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2f8405d8-8099-4182-8010-0701abbe44f4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Tutorial missing import: Http404
On Friday, April 10, 2015 at 3:33:36 PM UTC-7, Ramiro Morales wrote: > > On Fri, Apr 10, 2015 at 6:31 PM, John Matthew Ian Davis < > johnmatth...@gmail.com > wrote: > >> obviously one needs to change: >> >> from django.http import HttpResponse, >> >> to >> >> from django.http import HttpResponse, Http404 >> > > If you are talking about part 3 of the tutorial then it in fact contains > an import of Http404 and it's intrdroduced together with the first piece of > code that uses it. > > It's right in the views.py snippet located under the "Raising a 404 error" > section title: > https://docs.djangoproject.com/en/1.8/intro/tutorial03/#raising-a-404-error > > Regards, > > -- > Ramiro Morales > @ramiromorales > You (and the page) are completely correct, and I missed the relevant line, reading through, a half dozen times in a row. Apologies. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c18b8de4-0895-49e4-86a0-a44dc3be7ee1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.