Django Form ChoiceField, initial not working
Hi, i have a simple form: class StoreLocationHoursForm(BForm): location = forms.ChoiceField(required=True) day = forms.ChoiceField(choices=bagit_constants.dow,required=True) time_open_hours = forms.ChoiceField(choices=constants.hours,required=True) time_open_minutes = forms.ChoiceField(choices=constants.minutes,required=True) time_close_hours = forms.ChoiceField(choices=constants.hours,required=True) time_close_minutes = forms.ChoiceField(choices=constants.minutes,required=True) there can be many locations, so in my view i loop through them to create a list of tuples to provide a choices list for location: Log Output of the list when im done:sl_list= [('-', 'Choose Location'), (u'Super City', u'901 PHILADELPHIA STREET')] the code i use to set initial is the following: form = StoreLocationHoursForm(initial={"location":sl_list}) However my select is empty when it renders the HTML. Thanks for the help in advance, j -- 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: List compare is there something better than a double loop?
very cool thanks, i knew it was a lack of api knowledge on my part. On Dec 2, 10:53 pm, Aaron Sterlingwrote: > > I'm building a store that has a product_list (class ProductList: > > store, name, description) that contains .products (class Product: > > name, description, price etc...) > > If you're expecting them to be in the same order, you could do > > all(product == cartitem.product for product, cartitem in > itertools.izip(cartitems, products)) > > This would be True if they're the same and false otherwise. If you want an > order insensitive comparison, you have: > > set(products) == set(cartitem.product for cartitem in cartitems) -- 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.
List compare is there something better than a double loop?
Hi, I probably have a common problem and maybe i'm not thinking about this correctly, but here it is. I'm building a store that has a product_list (class ProductList: store, name, description) that contains .products (class Product: name, description, price etc...) I also have a cart that is built out of (class CartItem: product, user, qty). when the store page loads with the products I want to acknowledge that the item being shown is in the cart. So when i get the cart i have a result of [cartitem,cartitem,cartitem] and i have a product_list of [product,product,product,...] So the simpleton in me wants to do a double loop (cart/product_list) and compare product == cartitem.product if so, do something. But it seems there should be a better way to do that, and if not, do i need to make a third list or can i put a transient field on product like product.qty_in_cart to pass down to my page for testing? Thanks j -- 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: can't import any of my libraries inside of my app folder
disregard, i didn't change my code, but my IDE did. fyi: "python manage.py shell" actually showed me the exact error. On Aug 18, 12:18 pm, Sector7B <joe.greenaw...@gmail.com> wrote: > **Disclaimer i'm using Django for GAE, but i really think this is a > Django thing** > > Last night i had a bunch of code working, did a commit went to bed. > Got up this morning and started my django app and suddenly any library > i try to import from myapp fails with something like this: > > "Could not import main_site.views.test. Error was: cannot import name > Store" > > In the following mess it shows my Python Path including my working > django project folder > Python Path: ['/Users/username/Documents/MyApp'...] > > my imports are like: > from bagitlib import libform as lf > from main_site.models import Store > > bagitlib & main_site being folders under MyApp. > > I thought maybe i broke something, but i haven't changed the code, and > the failure will happen at the very first import from MyApp, meaning > if i move around the imports the fail message moves. > > these imports seem to work: > from google.appengine.api import memcache > from django.utils.datastructures import MultiValueDictKeyError > import logging > > Thoughts? > > Thanks, > joe -- 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.
can't import any of my libraries inside of my app folder
**Disclaimer i'm using Django for GAE, but i really think this is a Django thing** Last night i had a bunch of code working, did a commit went to bed. Got up this morning and started my django app and suddenly any library i try to import from myapp fails with something like this: "Could not import main_site.views.test. Error was: cannot import name Store" In the following mess it shows my Python Path including my working django project folder Python Path:['/Users/username/Documents/MyApp'...] my imports are like: from bagitlib import libform as lf from main_site.models import Store bagitlib & main_site being folders under MyApp. I thought maybe i broke something, but i haven't changed the code, and the failure will happen at the very first import from MyApp, meaning if i move around the imports the fail message moves. these imports seem to work: from google.appengine.api import memcache from django.utils.datastructures import MultiValueDictKeyError import logging Thoughts? Thanks, joe -- 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: using django for google appengine, noob to both.
Felippe, Thank you for our feedback, I've posted this question over to the group you mentioned a couple replies ago, still waiting approval from the moderators but if you feel like continuing this I'd appreciate it. It might be helpful to others in the future. Malcom, I briefly looked over the site, very interesting, I'm going to continue. Thanks much. Joe On Jul 1, 12:10 am, Malcolm MacKinnon <mmack3...@gmail.com> wrote: > You should look at this site: > > http://www.allbuttonspressed.com/projects/django-nonrel > > <http://www.allbuttonspressed.com/projects/django-nonrel>I recommend it over > any other django appengine ORM I've tried. I think it can help you with some > of your issues. The blog and discussion group is very active and > informative. > > On Wed, Jun 30, 2010 at 5:03 PM, Felippe Bueno <felippe.bu...@gmail.com>wrote: > > > > > You can... but there are some limitations. > > For example, django's admin site, don't work using appengine > > You need to use db.Model, > > You need to use google.appengine.ext.db.djangoforms to validate forms... > > And some more > > > Btw, I think its better we discuss this using private messages, or at > > app-engine-django group (http://groups.google.com/group/app-engine-django > > ) :) > > > I mean, maybe we are bothering the members, talking more about appengine, > > than django. > > > On Wed, Jun 30, 2010 at 8:44 PM, Sector7B <joe.greenaw...@gmail.com>wrote: > > >> interestingly though, i guess my problem is still that i'm not able to > >> do the django way of things, which I thought was idea behind doing it > >> like this: > >>http://code.google.com/appengine/articles/appengine_helper_for_django... > > >> On Jun 30, 7:30 pm, Sector7B <joe.greenaw...@gmail.com> wrote: > >> > i was just coming to write that, lol. I opened up the code and read > >> > it! What a novel approach. > > >> > Thanks for pointer, i'm going to try again. > > >> > On Jun 30, 7:17 pm, Felippe Bueno <felippe.bu...@gmail.com> wrote: > > >> > > BaseModel extends db.Model :) > > >> > >http://stackoverflow.com/questions/1720157/diference-between-appengin. > >> .. > > >> > > On Wed, Jun 30, 2010 at 8:09 PM, Sector7B <joe.greenaw...@gmail.com> > >> wrote: > >> > > > Thank you for your reply. I gave it a try, and it didn't seem to > >> > > > work. The helper project (according to the introductory article) > >> has > >> > > > me using their "BaseModel", which I think is supposed to revert me > >> > > > back to using Django code. However there seems to be very little > >> > > > written beyond that article, although it is a good one. I went back > >> > > > to the site, they have a google group specifically for this set up, > >> > > > I'm going to post over to that group now. Thanks again. > > >> > > > Joe > > >> > > > On Jun 30, 3:12 pm, Felippe Bueno <felippe.bu...@gmail.com> wrote: > >> > > > > I think (THINK) you problem is with the db.Model > > >> > > > > Take a look athttp:// > >> > > > code.google.com/appengine/docs/python/datastore/queryclass.htm... > > >> > > > > < > >>http://code.google.com/appengine/docs/python/datastore/queryclass.htm.. > >> > > > .>You > >> > > > > will see that db.Model don't have the filter method, db.Query have > >> it. > >> > > > > You need to do some think like: > >> > > > > a = XItUser.all() > >> > > > > a.filter('xit_nickname =', 'awesome') > > >> > > > > I'm not sure if there is another way > > >> > > > > On Wed, Jun 30, 2010 at 4:04 PM, Sector7B < > >> joe.greenaw...@gmail.com> > >> > > > wrote: > >> > > > > > Hi, I'm using django on google appengine using this: > > >>http://code.google.com/appengine/articles/appengine_helper_for_django. > >> > > > .. > > >> > > > > > So I have my models, and I can load my pages and templates, and > >> > > > > > started to do some rudimentary object creates and gets inside > >> the > >> > > > > > shell (python manage.py shell) and my views to get a feel for > >> the > >> > > > > > API. Immediately Im coming across errors, whi
Re: using django for google appengine, noob to both.
interestingly though, i guess my problem is still that i'm not able to do the django way of things, which I thought was idea behind doing it like this: http://code.google.com/appengine/articles/appengine_helper_for_django.html On Jun 30, 7:30 pm, Sector7B <joe.greenaw...@gmail.com> wrote: > i was just coming to write that, lol. I opened up the code and read > it! What a novel approach. > > Thanks for pointer, i'm going to try again. > > On Jun 30, 7:17 pm, Felippe Bueno <felippe.bu...@gmail.com> wrote: > > > > > BaseModel extends db.Model :) > > >http://stackoverflow.com/questions/1720157/diference-between-appengin... > > > On Wed, Jun 30, 2010 at 8:09 PM, Sector7B <joe.greenaw...@gmail.com> wrote: > > > Thank you for your reply. I gave it a try, and it didn't seem to > > > work. The helper project (according to the introductory article) has > > > me using their "BaseModel", which I think is supposed to revert me > > > back to using Django code. However there seems to be very little > > > written beyond that article, although it is a good one. I went back > > > to the site, they have a google group specifically for this set up, > > > I'm going to post over to that group now. Thanks again. > > > > Joe > > > > On Jun 30, 3:12 pm, Felippe Bueno <felippe.bu...@gmail.com> wrote: > > > > I think (THINK) you problem is with the db.Model > > > > > Take a look athttp:// > > > code.google.com/appengine/docs/python/datastore/queryclass.htm... > > > > > <http://code.google.com/appengine/docs/python/datastore/queryclass.htm.. > > > .>You > > > > will see that db.Model don't have the filter method, db.Query have it. > > > > You need to do some think like: > > > > a = XItUser.all() > > > > a.filter('xit_nickname =', 'awesome') > > > > > I'm not sure if there is another way > > > > > On Wed, Jun 30, 2010 at 4:04 PM, Sector7B <joe.greenaw...@gmail.com> > > > wrote: > > > > > Hi, I'm using django on google appengine using this: > > > > >http://code.google.com/appengine/articles/appengine_helper_for_django. > > > .. > > > > > > So I have my models, and I can load my pages and templates, and > > > > > started to do some rudimentary object creates and gets inside the > > > > > shell (python manage.py shell) and my views to get a feel for the > > > > > API. Immediately Im coming across errors, which seem weird since > > > > > their so simple, and right out of the sample docs. (http:// > > > > > docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-queries) > > > > > I'm guessing i have setup or import problem? Or I'm missing something > > > > > major with the appengine way of things, but I am under the impression > > > > > after the setup it should run the same. Either way maybe someone can > > > > > tell me better. > > > > > > Thanks, > > > > > j > > > > > > >>> b = XItUser(xit_nickname="awesome") > > > > > >>> b.save() > > > > > datastore_types.Key.from_path(u'XItUser', 2L, _app=u'xitforme') > > > > > >>> b > > > > > XItUser(**{x_user': None, 'xit_nickname': 'awesome'}) > > > > > >>> x = XItUser.objects.filter(xit_nickname="awesome") > > > > > Traceback (most recent call last): > > > > > File "", line 1, in > > > > > File ".../models.py", line 37, in __getattr__ > > > > > return getattr(self.owner, name) > > > > > AttributeError: type object 'XItUser' has no attribute 'filter' > > > > > >>> x = XItUser.objects.get(xit_nickname="awesome") > > > > > Traceback (most recent call last): > > > > > File "", line 1, in > > > > > TypeError: get() takes exactly 2 non-keyword arguments (1 given) > > > > > >>> x = XItUser.objects.filter(xit_nickname__iexact="awesome") > > > > > Traceback (most recent call last): > > > > > File "", line 1, in > > > > > File ".../models.py", line 37, in __getattr__ > > > > > return getattr(self.owner, name) > > > > > AttributeError: type object 'XItUser' has no attribute 'filter' > > > > > > -- > > > > > You received this message becau
Re: using django for google appengine, noob to both.
i was just coming to write that, lol. I opened up the code and read it! What a novel approach. Thanks for pointer, i'm going to try again. On Jun 30, 7:17 pm, Felippe Bueno <felippe.bu...@gmail.com> wrote: > BaseModel extends db.Model :) > > http://stackoverflow.com/questions/1720157/diference-between-appengin... > > > > On Wed, Jun 30, 2010 at 8:09 PM, Sector7B <joe.greenaw...@gmail.com> wrote: > > Thank you for your reply. I gave it a try, and it didn't seem to > > work. The helper project (according to the introductory article) has > > me using their "BaseModel", which I think is supposed to revert me > > back to using Django code. However there seems to be very little > > written beyond that article, although it is a good one. I went back > > to the site, they have a google group specifically for this set up, > > I'm going to post over to that group now. Thanks again. > > > Joe > > > On Jun 30, 3:12 pm, Felippe Bueno <felippe.bu...@gmail.com> wrote: > > > I think (THINK) you problem is with the db.Model > > > > Take a look athttp:// > > code.google.com/appengine/docs/python/datastore/queryclass.htm... > > > > <http://code.google.com/appengine/docs/python/datastore/queryclass.htm.. > > .>You > > > will see that db.Model don't have the filter method, db.Query have it. > > > You need to do some think like: > > > a = XItUser.all() > > > a.filter('xit_nickname =', 'awesome') > > > > I'm not sure if there is another way > > > > On Wed, Jun 30, 2010 at 4:04 PM, Sector7B <joe.greenaw...@gmail.com> > > wrote: > > > > Hi, I'm using django on google appengine using this: > > > >http://code.google.com/appengine/articles/appengine_helper_for_django. > > .. > > > > > So I have my models, and I can load my pages and templates, and > > > > started to do some rudimentary object creates and gets inside the > > > > shell (python manage.py shell) and my views to get a feel for the > > > > API. Immediately Im coming across errors, which seem weird since > > > > their so simple, and right out of the sample docs. (http:// > > > > docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-queries) > > > > I'm guessing i have setup or import problem? Or I'm missing something > > > > major with the appengine way of things, but I am under the impression > > > > after the setup it should run the same. Either way maybe someone can > > > > tell me better. > > > > > Thanks, > > > > j > > > > > >>> b = XItUser(xit_nickname="awesome") > > > > >>> b.save() > > > > datastore_types.Key.from_path(u'XItUser', 2L, _app=u'xitforme') > > > > >>> b > > > > XItUser(**{x_user': None, 'xit_nickname': 'awesome'}) > > > > >>> x = XItUser.objects.filter(xit_nickname="awesome") > > > > Traceback (most recent call last): > > > > File "", line 1, in > > > > File ".../models.py", line 37, in __getattr__ > > > > return getattr(self.owner, name) > > > > AttributeError: type object 'XItUser' has no attribute 'filter' > > > > >>> x = XItUser.objects.get(xit_nickname="awesome") > > > > Traceback (most recent call last): > > > > File "", line 1, in > > > > TypeError: get() takes exactly 2 non-keyword arguments (1 given) > > > > >>> x = XItUser.objects.filter(xit_nickname__iexact="awesome") > > > > Traceback (most recent call last): > > > > File "", line 1, in > > > > File ".../models.py", line 37, in __getattr__ > > > > return getattr(self.owner, name) > > > > AttributeError: type object 'XItUser' has no attribute 'filter' > > > > > -- > > > > 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<django-users%2bunsubscr...@google > > > > groups.com> > > <django-users%2bunsubscr...@google groups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@google > > groups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: using django for google appengine, noob to both.
Thank you for your reply. I gave it a try, and it didn't seem to work. The helper project (according to the introductory article) has me using their "BaseModel", which I think is supposed to revert me back to using Django code. However there seems to be very little written beyond that article, although it is a good one. I went back to the site, they have a google group specifically for this set up, I'm going to post over to that group now. Thanks again. Joe On Jun 30, 3:12 pm, Felippe Bueno <felippe.bu...@gmail.com> wrote: > I think (THINK) you problem is with the db.Model > > Take a look > athttp://code.google.com/appengine/docs/python/datastore/queryclass.htm... > > <http://code.google.com/appengine/docs/python/datastore/queryclass.htm...>You > will see that db.Model don't have the filter method, db.Query have it. > You need to do some think like: > a = XItUser.all() > a.filter('xit_nickname =', 'awesome') > > I'm not sure if there is another way > > > > On Wed, Jun 30, 2010 at 4:04 PM, Sector7B <joe.greenaw...@gmail.com> wrote: > > Hi, I'm using django on google appengine using this: > >http://code.google.com/appengine/articles/appengine_helper_for_django... > > > So I have my models, and I can load my pages and templates, and > > started to do some rudimentary object creates and gets inside the > > shell (python manage.py shell) and my views to get a feel for the > > API. Immediately Im coming across errors, which seem weird since > > their so simple, and right out of the sample docs. (http:// > > docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-queries) > > I'm guessing i have setup or import problem? Or I'm missing something > > major with the appengine way of things, but I am under the impression > > after the setup it should run the same. Either way maybe someone can > > tell me better. > > > Thanks, > > j > > > >>> b = XItUser(xit_nickname="awesome") > > >>> b.save() > > datastore_types.Key.from_path(u'XItUser', 2L, _app=u'xitforme') > > >>> b > > XItUser(**{x_user': None, 'xit_nickname': 'awesome'}) > > >>> x = XItUser.objects.filter(xit_nickname="awesome") > > Traceback (most recent call last): > > File "", line 1, in > > File ".../models.py", line 37, in __getattr__ > > return getattr(self.owner, name) > > AttributeError: type object 'XItUser' has no attribute 'filter' > > >>> x = XItUser.objects.get(xit_nickname="awesome") > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: get() takes exactly 2 non-keyword arguments (1 given) > > >>> x = XItUser.objects.filter(xit_nickname__iexact="awesome") > > Traceback (most recent call last): > > File "", line 1, in > > File ".../models.py", line 37, in __getattr__ > > return getattr(self.owner, name) > > AttributeError: type object 'XItUser' has no attribute 'filter' > > > -- > > 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<django-users%2bunsubscr...@google > > groups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
using django for google appengine, noob to both.
Hi, I'm using django on google appengine using this: http://code.google.com/appengine/articles/appengine_helper_for_django.html So I have my models, and I can load my pages and templates, and started to do some rudimentary object creates and gets inside the shell (python manage.py shell) and my views to get a feel for the API. Immediately Im coming across errors, which seem weird since their so simple, and right out of the sample docs. (http:// docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-queries) I'm guessing i have setup or import problem? Or I'm missing something major with the appengine way of things, but I am under the impression after the setup it should run the same. Either way maybe someone can tell me better. Thanks, j >>> b = XItUser(xit_nickname="awesome") >>> b.save() datastore_types.Key.from_path(u'XItUser', 2L, _app=u'xitforme') >>> b XItUser(**{x_user': None, 'xit_nickname': 'awesome'}) >>> x = XItUser.objects.filter(xit_nickname="awesome") Traceback (most recent call last): File "", line 1, in File ".../models.py", line 37, in __getattr__ return getattr(self.owner, name) AttributeError: type object 'XItUser' has no attribute 'filter' >>> x = XItUser.objects.get(xit_nickname="awesome") Traceback (most recent call last): File "", line 1, in TypeError: get() takes exactly 2 non-keyword arguments (1 given) >>> x = XItUser.objects.filter(xit_nickname__iexact="awesome") Traceback (most recent call last): File "", line 1, in File ".../models.py", line 37, in __getattr__ return getattr(self.owner, name) AttributeError: type object 'XItUser' has no attribute 'filter' -- 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: noob syntax question
very nice, thank you. I will look up the book. On Jun 24, 2:37 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Jun 24, 7:01 pm, Sector7B <joe.greenaw...@gmail.com> wrote: > > > Thanks for the feedback and the link, all good stuff! > > I looked at what i had written, and I think a better way to ask the > > question is: > > What are the mechanics behind providing "choice_set.all()"? > > For example i have a field "choice" so having "_set" (concatenated) is > > that generated when i run syncdb somewhere, or is that dynamically > > interpreted at runtime? > > My background leads me to think there would be a choice.set().all(), > > the "_set" seems weird (to me) unless its generated. > > > Thanks again, > > -j > > It's dynamically generated when the model class is defined. Fields can > define a 'contribute_to_class' method, which is responsible for > defining dynamic properties/methods on the model class. When the field > is instantiated - which happens when the class is defined, ie when its > module is first imported - the field's contribute_to_class method is > executed and the related manager is created. You can see the code for > this in django.db.models.fields.related.RelatedField. (Actually you'll > see that contribute_to_class calls do_related_class, which calls > contribute_to_related_class, which sets up the descriptor on the > related model.) > > A very good guide to all this is Marty Alchin's book Pro Django, which > goes into depth as to how the model metaclasses work. > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: noob syntax question
Thanks for the feedback and the link, all good stuff! I looked at what i had written, and I think a better way to ask the question is: What are the mechanics behind providing "choice_set.all()"? For example i have a field "choice" so having "_set" (concatenated) is that generated when i run syncdb somewhere, or is that dynamically interpreted at runtime? My background leads me to think there would be a choice.set().all(), the "_set" seems weird (to me) unless its generated. Thanks again, -j On Jun 24, 3:09 am, "euan.godd...@googlemail.com" <euan.godd...@gmail.com> wrote: > I'd add to Michael's comment that if you're unhappy with this syntax > (I personally find it a bit odd in some cases), you can customize > exactly what word is used there in your model definition. > > If you alter the choice model and add the "related_name" keyword to > the foreign key definition, e.g.: > > class Choice(models.Model): > ... > poll = models.ForeignKey(Poll, related_name="choices") > > you can then do: > > >>> p.choices.create(...) > > On 23 June, 23:17, Michael Schade <mich...@mschade.me> wrote: > > > > > (Sorry in advance for the brevity and any typos, I am typing this from > > my aging Windows Mobile). > > > It's quite Django-specific actually. If you take a look > > athttp://docs.djangoproject.com/en/dev/topics/db/queries/ it says, > > "Django also creates API accessors for the "other" side of the > > relationship -- the link from the related model to the model that > > defines the relationship. For example, a Blog object b has access to a > > list of all related Entry objects via the entry_set attribute: > > b.entry_set.all()." > > > Hope that clears things up. > > > Michael Schade > > Spearhead Development LLC > > > On 6/23/10, Sector7B <joe.greenaw...@gmail.com> wrote: > > > > Hi, > > > In the tutorial 1. > > > > It has this: > > > # Give the Poll a couple of Choices. The create call constructs a new > > > # choice object, does the INSERT statement, adds the choice to the set > > > # of available choices and returns the new Choice object. Django > > > creates > > > # a set to hold the "other side" of a ForeignKey relation > > > # (e.g. a poll's choices) which can be accessed via the API. > > > > and gives these examples: > > > # Create three choices. > > >>>> p.choice_set.create(choice='Not much', votes=0) > > > > > >>>> p.choice_set.create(choice='The sky', votes=0) > > > > > >>>> c = p.choice_set.create(choice='Just hacking again', votes=0) > > > > I understand what its doing, but I don't understand where the "_set" > > > comes from or where its resolved to. > > > Its probably more of a python thing than a django thing, but if > > > someone could provide insight, it would be much appreciate. > > > > Thanks, > > > -j > > > > -- > > > 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. > > > -- > > Sincerely, > > Michael Schadewww.mschade.me-815.514.1410 -- 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.
noob syntax question
Hi, In the tutorial 1. It has this: # Give the Poll a couple of Choices. The create call constructs a new # choice object, does the INSERT statement, adds the choice to the set # of available choices and returns the new Choice object. Django creates # a set to hold the "other side" of a ForeignKey relation # (e.g. a poll's choices) which can be accessed via the API. and gives these examples: # Create three choices. >>> p.choice_set.create(choice='Not much', votes=0) >>> p.choice_set.create(choice='The sky', votes=0) >>> c = p.choice_set.create(choice='Just hacking again', votes=0) I understand what its doing, but I don't understand where the "_set" comes from or where its resolved to. Its probably more of a python thing than a django thing, but if someone could provide insight, it would be much appreciate. Thanks, -j -- 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: Problem setting up mysqldb 1.2.3c1 on Mac 10.5.8 Leopard
I had this same problem, i eventually abandoned building any of it manually and switched to macports: http://groups.google.com/group/django-users/browse_thread/thread/862ceed6f97acf1c/eeff8aa5fb16ca0c#eeff8aa5fb16ca0c. If you read the thread no one agrees with me, but its working great for me so far. Since I'm a noob as well, it could prove a mistake down the road. However I did fix the build problem before i abandoned it. I had to make some symbolic links so that /usr/local/mysql pointed to my actual install where mysql was installed. riuxjg:local jgreenaw$ ls -l /usr/local/mysql/ total 8 lrwxr-xr-x 1 root wheel 27 Jan 20 14:01 lib -> /opt/local/lib/ mysql5/mysql so something like this: cd /usr/local sudo ln -s opt/local/lib/mysql5/mysql mysql If you look in the build its actually looking for the _mysql.so file which is somewhere in your mysql install directory. hope it helps. On Feb 5, 7:40 am, monchiwrote: > Hi there, > > I'm a first time Django user, trying to set up Django on my Mac 10.5.8 > Leopard with MySQL from MAMP. > Is this actually possible? > > I managed to get the welcome message from Django install, so that's > working, I assume. > > Next, MySQL, I got this: > >>> import MYSQLdb > > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named MYSQLdb > > > I went and downloaded the mysql-python-1.2.3c1, unpacked it, tried to > build it, and got this error: > > > running build > running build_py > copying MySQLdb/release.py -> build/lib.macosx-10.5-i386-2.5/MySQLdb > running build_ext > building '_mysql' extension > gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc > build/temp.macosx-10.5-i386-2.5/_mysql.o -L/Applications/MAMP/Library/ > lib/mysql -lmysqlclient_r -lz -lm -o build/lib.macosx-10.5-i386-2.5/ > _mysql.so > ld: library not found for -lmysqlclient_r > collect2: ld returned 1 exit status > ld: library not found for -lmysqlclient_r > collect2: ld returned 1 exit status > lipo: can't open input file: /var/folders/sE/sEdFajpBFXergJVaiXZyfU++ > +TI/-Tmp-//cc1NtAuY.out (No such file or directory) > error: command 'gcc' failed with exit status 1 > > > I also tried the older version, mysql-python-1.2.2, got the unsigned > error, commented out lines 37-39 as suggested by many, which worked, > but got this similar error: > > > running build > running build_py > copying MySQLdb/release.py -> build/lib.macosx-10.5-i386-2.5/MySQLdb > running build_ext > building '_mysql' extension > gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused- > madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes - > DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe - > Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/Applications/ > MAMP/Library/include/mysql -I/System/Library/Frameworks/ > Python.framework/Versions/2.5/include/python2.5 -c _mysql.c -o build/ > temp.macosx-10.5-i386-2.5/_mysql.o -fno-omit-frame-pointer - > D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ - > DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL > gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc > build/temp.macosx-10.5-i386-2.5/_mysql.o -L/Applications/MAMP/Library/ > lib/mysql -lmysqlclient_r -lz -lm -o build/lib.macosx-10.5-i386-2.5/ > _mysql.so > ld: library not found for -lmysqlclient_r > collect2: ld returned 1 exit status > ld: library not found for -lmysqlclient_r > collect2: ld returned 1 exit status > lipo: can't open input file: /var/folders/sE/sEdFajpBFXergJVaiXZyfU++ > +TI/-Tmp-//ccV4OFgQ.out (No such file or directory) > error: command 'gcc' failed with exit status 1 > > > How can I get around the "ld: library not found for -lmysqlclient_r" > error? > What am I missing or doing wrong? > > Many have also suggested to use SQLite. At this rate I'm willing to > give it a try, though I would much prefer MySQL MAMP/XAMPP alternative > if it's possible at all. > > Thanks for your help, I'm looking forward to your advise. -- 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: A Couple Newbie Questions
thanks, sys.path.append('/path/to') is what i have, and the polls url worked. On Jan 31, 12:27 am, Dave Murphy <d...@schwuk.com> wrote: > On 30 January 2010 19:59, Sector7B <joe.greenaw...@gmail.com> wrote: > > > 1. Reading the documentation for deploying using mod_wsgi. It says > > not to use just 'settings' in django.wsgi The example has > > sys.path.append('/path/to/app/mysite') > > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'. > > this doesn't work because of namespace path problems, my workaround > > is: > > sys.path.append('/path/to/app') > > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' > > My fear is that it would put multiple projects into play under /path/ > > to/app like /path/to/app/mysite2 etc... The bigger question is my > > solution doesn't match the examples. > > If you're app is called mysite, and it's hosted at '/path/to/mysite' > your .wsgi should contain: > > sys.path.append('/path/to') > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'. > > This is what I use, and it works for me. > > Read and digest this - it has more information than the Django docs > one:http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango > > > 4. After deploying to apache, in my virtual host i have: > > WSGIScriptAlias / /opt/local/www/mysite/apache/django.wsgi. Thinking > > thathttp://dev.polls.comwould take me right to the polls app. > > However I still have to dohttp://dev.polls.com/pollsto get to polls > > app. > > Assuming you've followed the tutorial to the letter, and are using app > specific urls.py, simply change your urlpattern in the site urls.py > from: > > (r'^polls/', include('mysite.polls.urls')) > > to > > (r'', include('mysite.polls.urls')) > > Note that this should be the last pattern you declare, otherwise it > will override the over patterns. -- 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.
A Couple Newbie Questions
Hi, got a couple questions after the getting started. I've followed the tutorial and have it deployed to an apache instance locally. But planning out my next steps for my app, i have some questions hopefully someone can add insight to. 1. Reading the documentation for deploying using mod_wsgi. It says not to use just 'settings' in django.wsgi The example has sys.path.append('/path/to/app/mysite') os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'. this doesn't work because of namespace path problems, my workaround is: sys.path.append('/path/to/app') os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' My fear is that it would put multiple projects into play under /path/ to/app like /path/to/app/mysite2 etc... The bigger question is my solution doesn't match the examples. 2. Under the mysite project i have the polls app. Lets say I want to create polls-mobile, and reuse all the data and models from polls. Do i just import polls.poll inside polls-mobile? Is that the standard practice? 3. Authentication, I have read the benefits to authentication model and using the django.User object. I'd like to employ that into my apps, but it seems that maybe the django.User object is more suited for the project and not for the apps. If my polls app is going to require logins for usage, should i use the django.User and built in authentication scheme or build something poll specific for security reasons. It seems one wrong check (e.g. superuser) and I inadvertently allow someone admin access to the site. 4. After deploying to apache, in my virtual host i have: WSGIScriptAlias / /opt/local/www/mysite/apache/django.wsgi. Thinking that http://dev.polls.com would take me right to the polls app. However I still have to do http://dev.polls.com/polls to get to polls app. Thanks in advance for any info. -j -- 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.