Re: WebFaction + Django Fixture: Help?
Thanks, Andy. New problem... I've recreated the problem locally on postgres. But I've gone back to sqlite3 and the loaddata works from scratch. Is there a way I can tell which items from the sqlite3 db is giving me problems in postgres? Thank you! Keyton On Jun 17, 3:51 pm, Andy McKay wrote: > On 17-Jun-09, at 12:48 PM, Keyton Weissinger wrote: > > > backends/util.py", line 19, in execute > > return self.cursor.execute(sql, params) > > DataError: value too long for type character varying(4) > > > Any ideas? > > The unhelpful answer is that the field is too long. One way to get > this is to have a different database schema at home from on the > webfaction server. Double check your schema in postgres the same as > home, chances are something has changed. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
WebFaction + Django Fixture: Help?
I have a nice test fixture that loads my local database without incident. I'm using postgresql 8.3 at home on ubuntu. I use the fixture at home all the time. Trying to run it on webfaction, I get the following error: [key...@web58 schoolicity]$ python2.5 manage.py loaddata full_load.json Installing json fixture 'full_load' from absolute path. Problem installing fixture 'full_load.json': Traceback (most recent call last): File "/home/keyton/webapps/django_test/lib/python2.5/django/core/ management/commands/loaddata.py", line 119, in handle obj.save() File "/home/keyton/webapps/django_test/lib/python2.5/django/core/ serializers/base.py", line 163, in save models.Model.save_base(self.object, raw=True) File "/home/keyton/webapps/django_test/lib/python2.5/django/db/ models/base.py", line 383, in save_base result = manager._insert(values, return_id=update_pk) File "/home/keyton/webapps/django_test/lib/python2.5/django/db/ models/manager.py", line 138, in _insert return insert_query(self.model, values, **kwargs) File "/home/keyton/webapps/django_test/lib/python2.5/django/db/ models/query.py", line 894, in insert_query return query.execute_sql(return_id) File "/home/keyton/webapps/django_test/lib/python2.5/django/db/ models/sql/subqueries.py", line 309, in execute_sql cursor = super(InsertQuery, self).execute_sql(None) File "/home/keyton/webapps/django_test/lib/python2.5/django/db/ models/sql/query.py", line 1734, in execute_sql cursor.execute(sql, params) File "/home/keyton/webapps/django_test/lib/python2.5/django/db/ backends/util.py", line 19, in execute return self.cursor.execute(sql, params) DataError: value too long for type character varying(4) Any ideas? Thank you! Keyton --~--~-~--~~~---~--~~ 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: Using Request Info in Generic Views
http://groups.google.com/group/django-users/browse_thread/thread/bde817d4620fdfec On Tue, Jun 2, 2009 at 7:33 AM, Keyton Weissinger wrote: > I know I'm in the minority, but I'm still having some trouble grokking > the details of generic views. I keep thinking I should be using them > but keep running into the same issue. > > Here's my problem: I am building a mgmt site for schools in which > schools sign up for a monthly service fee. Most of my models have a > "school" foreign key which is also part of the user's profile. > > So to see, for example, a list of teachers, I do something kind of > like this (assumes login has already occurred): > > def myview(request): > current_person = request.user.get_profile() > current_school = current_person.school > teacher_list = Teacher.objects.filter(school=current_school) > etc > > Almost everything I have has this school property. > > My question is this: How do I leverage generic views in this capacity? > Is there a way to use the request information (specifically > request.user.get_profile().school in my case) in my urls.py when > generating my querysets? > > Thank you! > > Keyton --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Using Request Info in Generic Views
I know I'm in the minority, but I'm still having some trouble grokking the details of generic views. I keep thinking I should be using them but keep running into the same issue. Here's my problem: I am building a mgmt site for schools in which schools sign up for a monthly service fee. Most of my models have a "school" foreign key which is also part of the user's profile. So to see, for example, a list of teachers, I do something kind of like this (assumes login has already occurred): def myview(request): current_person = request.user.get_profile() current_school = current_person.school teacher_list = Teacher.objects.filter(school=current_school) etc Almost everything I have has this school property. My question is this: How do I leverage generic views in this capacity? Is there a way to use the request information (specifically request.user.get_profile().school in my case) in my urls.py when generating my querysets? Thank you! Keyton --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Practical Django Projects 2nd Edition
Supposed to ship today, no? Has anyone heard of a delay? Keyton --~--~-~--~~~---~--~~ 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: Garbage Collection(maybe?) and RequestContext
Something deep inside kept telling me it was something like that. Grrr Love making the noob mistakes. NOT! ;-) Thanks DR! On Mar 24, 11:57 am, Daniel Roseman wrote: > On Mar 24, 3:42 pm, Keyton Weissinger wrote: > > > I'm using the extra_context dictionary passed into the view like many > > folks (James Bennett among them) seem to recommend either directly or > > via his projects. > > > Here is what a view might look like (all of this is on dpaste with > > link below if you'd prefer): > > > from django.shortcuts import render_to_response > > from django.template import RequestContext > > > def test_view(request, template_name='test_view.html', extra_context= > > {}): > > No need to read any further: you have run up against one of the > biggest Python gotchas. Never put a mutable type as a default argument > in a function call. This is because the definition is evaluated only > once, so you get the same values each time you call the function. More > explanation from the effbot here:http://effbot.org/zone/default-values.htm > > As that page shows, the answer is: > def test_view(request, template_name='test_view.html', > extra_context=None) > if extra_context is None: > extra_context = {} > > etc. > -- > 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-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 -~--~~~~--~~--~--~---
Garbage Collection(maybe?) and RequestContext
I'm using the extra_context dictionary passed into the view like many folks (James Bennett among them) seem to recommend either directly or via his projects. Here is what a view might look like (all of this is on dpaste with link below if you'd prefer): from django.shortcuts import render_to_response from django.template import RequestContext def test_view(request, template_name='test_view.html', extra_context= {}): if request.method == 'POST': print 'inside post code...' extra_context['extra_context_test'] = 'this is a test message' context = RequestContext(request) for key, value in extra_context.items(): context[key] = callable(value) and value() or value return render_to_response(template_name, {'form': None}, context_instance=context) Here's the template I'm using as well: Here is the current value of the extra_context item 'test': {{ extra_context_test }} Now, if I call this view for the first time, I get something like this in my browser (as expected): Here is the current value of the extra_context item 'test': [SUBMIT_BUTTON] I click the submit button and then I get something like this: Here is the current value of the extra_context item 'test': this is a test message [SUBMIT_BUTTON] So far so good. Based on my view this is exactly what I'd expect. Now. Open a completely new browser if possible (I did this with Firefox for the first two steps and then IE for this next step -- all on the same Windows XP box) and navigate to the same view (in my case: http://127.0.0.1:8000/test_view/). Yep, you get this again: Here is the current value of the extra_context item 'test': this is a test message [SUBMIT_BUTTON] NOTE: Existence of "this is a test message" text -- even though I didn't POST it this time. I have ensured that the POST portion of the view is not being called and yet the extra_context_test value in the extra_context dictionary still seems to have a value lingering. Now I assume that somehow magically extra_context is still in the request object or something, but I can't explain why. If I just move the extra_context piece out of the parameters, everything is ducky: def test_view(request, template_name='test_view.html'): # THIS WORKS AS EXPECTED BUT DOESN'T ALLOW ME TO PASS STUFF IN!!! extra_context={} if request.method == 'POST': print 'inside post code...' extra_context['extra_context_test'] = 'this is a test message' context = RequestContext(request) for key, value in extra_context.items(): context[key] = callable(value) and value() or value return render_to_response(template_name, {'form': None}, context_instance=context) I feel certain that there is some bigtime obvious Python or Django reason for this behavior but I've not found it. Thank you very much for any explanation you are able to provide. Best, Keyton Code here: http://dpaste.com/18518/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
unknown encoding: cp0 --> django\forms\forms.py in full_clean (241)
I'm running django on an Apache 2.2 server on a Windows XP box. I'm running django 1.0.2. I had a simple form/view that worked like a champ in my ubuntu box but now suddenly bombs in the django forms code. Here's the trace: http://dpaste.com/16330/ Looking at other instances of similar problems, in the past it appears to have occurred in trying to print something so I thought maybe it was a debug statement I had somewhere but I've ruled that out. Below are links to both the view function and the form I'm using. The form is a little funky because I'm adding a bunch of stuff for dojoTypes (if anyone knows a better way, lemme know -- and unfortunately it doesn't look like Dojango or Dojima help - argh!) but I don't think it's too terrible. Any ideas? Thank you... Keyton View: http://dpaste.com/16329/ Form: http://dpaste.com/16328/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
RELEASED: django-batchimport 0.2
Hi Folks, I've updated the django-batchimport project to version 0.2. This new version allows for easy import of relationship data (many-to-many, for example) for previously imported data -- even if your original data doesn't have unique IDs. There's also the new ability to override field values (say, using some property in the session or on the user's profile, for example) and several convenience methods... http://code.google.com/p/django-batchimport/ Take a look. Let me know if you have any problems. Best, Keyton django-batchimport: This application can be added to any django project to give it batch import capability via uploaded Microsoft Excel file (or other formats saved as XLS). This allows for someone with a spreadsheet of, say, users to easily upload it and add it all at once. While batch importing in django is easy to do via fixtures, this reusable app is aimed at being for non-developer end users of your web application. The process by which this app does it's work is completely dynamic, inspecting both the spreadsheet and the django models dynamically at runtime. No prior knowledge of either the model into which the user is importing or the spreadsheet uploaded is required. The only prerequisite is John Machin's xlrd library (http:// www.lexicon.net/sjmachin/xlrd.htm), python 2.5+, and django 1.0+. See the website for full details and please drop me a note on the django-batchimport-users group if you have questions or comments. --~--~-~--~~~---~--~~ 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: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
Hi Malcolm, Thank you VERY much for taking the time to explain this to me. It makes perfect sense and since yesterday I've delved a bit deeper (than ever) into the django code itself to understand a little more. You are ABSOLUTELY right to point out that I'm in user-beware country. I don't apologize for that so much. I think the batchimport project has some usefulness to folks and it's worth the risk -- **IF** I do it right. ;-) (if you think otherwise, PLEASE let me know) Even since yesterday I've begun a good scouring of the project to reduce touching the internals as much as possible. I apologize for not giving more details. I am always trying to balance giving enough information while trying to avoid scaring people away with too much detail. I didn't think it through enough I suppose. I kept being stymied by the thing "working" on the command line. My mistake. Anyway. I understand the whole thing MUCH better now and have already spent a little time reviewing the really "cutting edge" aspects of this project like, you know, "how lists work in python." ;-) Ugh. Kicking Myself Diligently, Keyton On Jan 22, 3:10 am, Malcolm Tredinnick wrote: > On Wed, 2009-01-21 at 19:38 -0800,KeytonWeissinger wrote: > > OK. I figured it out and it was VERY STRANGE. Maybe some one reading > > this can tell me WWWHHHYYY my solution works. For now, it's voodoo to > > me... > > You're going to kick yourself after this. The reason for the failure > turns out to be really easy to understand, now that your show the > code. :-) > > > > > Turns out that some of my code (in the view where I was having > > trouble) called some code that looked sort of like this: > > Hmm .. you didn't exactly simplify your failing case to the smallest > possible example, did you? All this extra stuff would have set off a lot > of alarm bells about other places to look (although my first thought > would have been whether you could do without it and retest to see if > that changed anything). > > Before getting into the more-or-less two line explanation, some > background information. Firstly, model._meta is obviously internal API, > so there are some shortcuts taken for performance and maintainability > reasons. We don't send the black helicopters after people who access it, > but it's very much "user beware" country. It's one of the areas that is > currently intentionally undocumented, for example (we'll eventually drop > some documentation about internal datastructures into docs/internals/, > but have had other things to do so far). > > Of relevance to this particular case, we use lists a lot internally and > return references to them from certain methods. We use lists, rather > than tuples, because they are updated a fair bit during creation and all > the extra copying isn't free (updating a tuple requires a copy). Lists > are just nicer to work with, generally. > > > field_list = model._meta.fields > > Have a look at the implementation here > (django.db.models.options.Options._fields(), since _meta.fields is a > property). It returns a reference to a list. A *reference*, not a copy! > > Your code would have worked if you wrote > > # Work with a copy of the fields list. > field_list = model._meta.fields[:] > > > field_list.extend(model._meta.many_to_many) > > Here you update that reference in place. So you've just corrupted one of > the internal data structures of self._meta. > > That's pretty much going to guarantee that the wheels will fall off at > some point in the future. If not in the way you saw, in some other > really hard to debug fashion. > > It's kind of a Python trap and if you're designing a public API, you > would generally return a copy of the list if the caller wasn't expected > to change the internal structure. In the Options class, we "know" (in > quotes, because there are people who call it from public code, but > that's their problem, not ours) that the only callers are functions that > are read-only on the data structure, so we save a bit of time and code > complexity. We could return a copy each time, but we access self._fields > a *lot*, particularly in queryset operations. Things might have changed > a bit in the last six months (although not dramatically), but when I was > working on the queryset-refactor branch, I spent a lot of time profiling > various common execution paths and a lot of the newer shared data > structures in Options are implemented based on that work (self.fields > used to be a simple list, for example, but when model inheritance came > in, it became, internally, more complicated). > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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-
Re: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
OK. I figured it out and it was VERY STRANGE. Maybe some one reading this can tell me WWWHHHYYY my solution works. For now, it's voodoo to me... Turns out that some of my code (in the view where I was having trouble) called some code that looked sort of like this: field_list = model._meta.fields field_list.extend(model._meta.many_to_many) for field in field_list: related_model_name = None related_model_app_name = None if (not field.name[-4:] == '_ptr') and (not field.__class__ == AutoField): if issubclass(field.__class__, related.RelatedField): if not field.__class__ == related.ForeignKey: related_model_app_name = field.rel.to.__module__.split ('.')[0] # We'll ignore all django-specific models (such as User, etc). if not related_model_app_name == 'django': related_model_name = field.rel.to.__name__ full_related_model_name = '.'.join ([field.rel.to.__module__, related_model_name]) relation_tuple_list.append((full_model_name +'%relation'+field.name+'%' + full_related_model_name, \ 'Mapping: ' + model.__name__ + '-' + \ related_model_name)) else: continue It is just pulling together a list of relationships between two models. I'm not using these models to actually DO anything. Just what you see. I could go to the command line and do the following: >>> from batchimport.forms import ImportOptionsForm >>> from sbase.models import Student >>> mydict = {'city': u'Columbus', 'first_name': u'Jimmy', 'last_name': >>> u'Jones', 'zip': 43215.0, 'title': u'Mr.', 'dob': '1956-12-29', >>> 'phone_primary': u'614-468-5940', 'state': u'OH', 'address': u'142, Quilly >>> Lane', 'type': u'Student', 'email': u'miles.l.ye...@spambob.com'} >>> mystudent = Student(**mydict) The import of ImportOptionsForms, it turns out, called the above code. OK. The above series of commands would fail every time with the following error. 'Student' instance needs to have a primary key value before a many-to- many relationship can be used. I was close. I could repeat my strange in-app problem on the command line. Yea. So after a LONG time of messing with it, it turns out that django didn't like how I was handling the many-to-many fields (model._meta.many_to_many). But I was able to fix my problem by just doing this: for field_list in [model._meta.fields, model._meta.many_to_many]: for field in field_list: related_model_name = None related_model_app_name = None if (not field.name[-4:] == '_ptr') and (not field.__class__ == AutoField): if issubclass(field.__class__, related.RelatedField): if not field.__class__ == related.ForeignKey: related_model_app_name = field.rel.to.__module__.split('.')[0] # We'll ignore all django-specific models (such as User, etc). if not related_model_app_name == 'django': related_model_name = field.rel.to.__name__ full_related_model_name = '.'.join ([field.rel.to.__module__, related_model_name]) relation_tuple_list.append((full_model_name +'%relation'+field.name+'%' + full_related_model_name, \ 'Mapping: ' + model.__name__ + '-' + \ related_model_name)) else: continue YEAH! That's all I changed. Instead of extending my list of fields with the many_to_many fields, I just iterated over one (to get the ForeignKey relationships etc, and then I subsequently iterated over my many-to-many fields. Why (the HELL) does the first version trigger this error: 'Student' instance needs to have a primary key value before a many-to- many relationship can be used. But the second version doesn't? If I'm an idiot, PLEASE tell me how so, because I'd really like to avoid this kind of quagmire if I can Thank you VERY MUCH Martin and Malcolm. I appreciate your respective looks at this problem very much. Your taking time to help with this kind of thorny issue is what makes this community rock and, frankly, inspires me to help out more. Keyton On Jan 21, 3:59 pm, Keyton Weissinger wrote: > Hmm. Thanks Martin. I will try with the SVN H
Re: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
Hmm. Thanks Martin. I will try with the SVN HEAD revision. I have already tried the Student(**mydict) approach and get the exact same issue. I will test tonight and respond. Thanks very much for taking time... Keyton On Jan 21, 3:24 pm, Martin Conte Mac Donell wrote: > Again, i can't reproduce your problem. > > It's working using SVN HEAD with your model and this > view:http://dpaste.com/111590/. Could you try to use that dict and > Student(**mydict) instead of > "model_import_info.model_for_import.objects.create" ? > > Regards, > M > > On Wed, Jan 21, 2009 at 3:06 PM, Keyton Weissinger wrote: > > > I'm on django 1.0.1 (NOT 1.0.2). Do you think that has any impact on > > this problem? I will try upgrading tonight. > > > Any other ideas? > > > K --~--~-~--~~~---~--~~ 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: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
I'm on django 1.0.1 (NOT 1.0.2). Do you think that has any impact on this problem? I will try upgrading tonight. Any other ideas? K On Jan 21, 8:33 am, Keyton Weissinger wrote: > More information... > > I stuck the following into my code at the same place the other code is > bombing. I did this just to make sure that I wasn't getting anything > weird in the dictionary here that I wasn't getting in the command > line. > > mydict = {'city': u'Columbus', 'first_name': u'Miles', 'last_name': > u'Yeung', 'school': import_object_dict['school'], 'zip': 43215.0, > 'title': u'Mr.', 'dob': '1956-12-29', 'phone_primary': > u'614-468-5940', 'state': u'OH', 'address': u'142, Quilly Lane', > 'type': u'Student', 'email': u'miles.l.ye...@spambob.com'} > > new_object = Student(**mydict) > > Same exact error as before. It's almost as if the Student object is > behaving differently within the context that it does within manage.py > shell. > > Just in case it was the school that was causing the issue above > (doubtful but good to rule it out) I tried the above WITHOUT the > school entry in the dictionary with the same results. > > Still stuck. > > Keyton > > On Jan 21, 8:13 am, Keyton Weissinger wrote:> Oh, and I > have printed the import_object_dict, it has exactly what I > > think it should... Argh! > > > ;-) > > > K > > > On Jan 21, 12:12 am, Martin Conte Mac Donell > > wrote: > > > > On Wed, Jan 21, 2009 at 2:35 AM, Keyton Weissinger > > > wrote: > > > > > Oh and just to re-state, this exact same code works like a champ on > > > > import of School or Parent data (neither of which have a ManyToMany > > > > field). > > > > > Keyton > > > > I can't reproduce this exception. Try to print import_object_dict just > > > before "new_object = > > > model_import_info.model_for_import.objects.create(**import_object_dict)". > > > > > Note that I am NOT yet trying to SAVE the Student object, just > > > > instantiate it. > > > > Actually Model.objects.create() do try to save() object. If you don't > > > want it, call Model(**import_object_dict) > > > > M. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
More information... I stuck the following into my code at the same place the other code is bombing. I did this just to make sure that I wasn't getting anything weird in the dictionary here that I wasn't getting in the command line. mydict = {'city': u'Columbus', 'first_name': u'Miles', 'last_name': u'Yeung', 'school': import_object_dict['school'], 'zip': 43215.0, 'title': u'Mr.', 'dob': '1956-12-29', 'phone_primary': u'614-468-5940', 'state': u'OH', 'address': u'142, Quilly Lane', 'type': u'Student', 'email': u'miles.l.ye...@spambob.com'} new_object = Student(**mydict) Same exact error as before. It's almost as if the Student object is behaving differently within the context that it does within manage.py shell. Just in case it was the school that was causing the issue above (doubtful but good to rule it out) I tried the above WITHOUT the school entry in the dictionary with the same results. Still stuck. Keyton On Jan 21, 8:13 am, Keyton Weissinger wrote: > Oh, and I have printed the import_object_dict, it has exactly what I > think it should... Argh! > > ;-) > > K > > On Jan 21, 12:12 am, Martin Conte Mac Donell > wrote: > > > On Wed, Jan 21, 2009 at 2:35 AM, Keyton Weissinger wrote: > > > > Oh and just to re-state, this exact same code works like a champ on > > > import of School or Parent data (neither of which have a ManyToMany > > > field). > > > > Keyton > > > I can't reproduce this exception. Try to print import_object_dict just > > before "new_object = > > model_import_info.model_for_import.objects.create(**import_object_dict)". > > > > Note that I am NOT yet trying to SAVE the Student object, just > > > instantiate it. > > > Actually Model.objects.create() do try to save() object. If you don't > > want it, call Model(**import_object_dict) > > > M. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
Oh, and I have printed the import_object_dict, it has exactly what I think it should... Argh! ;-) K On Jan 21, 12:12 am, Martin Conte Mac Donell wrote: > On Wed, Jan 21, 2009 at 2:35 AM, Keyton Weissinger wrote: > > > Oh and just to re-state, this exact same code works like a champ on > > import of School or Parent data (neither of which have a ManyToMany > > field). > > > Keyton > > I can't reproduce this exception. Try to print import_object_dict just > before "new_object = > model_import_info.model_for_import.objects.create(**import_object_dict)". > > > Note that I am NOT yet trying to SAVE the Student object, just instantiate > > it. > > Actually Model.objects.create() do try to save() object. If you don't > want it, call Model(**import_object_dict) > > M. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
Hi Martin, Thanks for the suggestion. I've tried it both ways to no avail. All, Here's the code from django.db.models.base.py (in the Model.__init__) where the trouble seems to start (around line 224): # Now we're left with the unprocessed fields that *must* come from # keywords, or default. print kwargs for field in fields_iter: print field.name rel_obj = None if kwargs: if isinstance(field.rel, ManyToOneRel): try: # Assume object instance was passed in. rel_obj = kwargs.pop(field.name) except KeyError: try: # Object instance wasn't passed in -- must be an ID. val = kwargs.pop(field.attname) except KeyError: val = field.get_default() else: # Object instance was passed in. Special case: You can # pass in "None" for related objects if it's allowed. if rel_obj is None and field.null: val = None else: val = kwargs.pop(field.attname, field.get_default ()) else: val = field.get_default() print field.name + ' default value ' + `val` # If we got passed a related instance, set it using the field.name # instead of field.attname (e.g. "user" instead of "user_id") so # that the object gets properly cached (and type checked) by the # RelatedObjectDescriptor. if rel_obj: setattr(self, field.name, rel_obj) else: setattr(self, field.attname, val) If I send in kwargs (and I've confirmed that it's getting what I think it's getting) it goes merrily along until it gets to my ManyToMany field at which time, it tries (using the last line above) to call setattr(self, field.attname, val) with None (the default value for the field). This triggers a call to the __set__ in related.py which in turn tries to call the __get__ to find my related object (diligently) and whammo. The thing's doing exactly what it's coded to do. My question is this: If I'm in the init for this model and the field's default value is None, why is the code ever trying to go get the related object? The code should know it's not there. Shouldn't there be a check somewhere in the stack to prevent the call to related.py in this case (in __init__ when I don't actually have a related object)? And why (the HECK) does this work just fine on the command line? That points to my code, but all my code is doing is generating the kwargs and feeding it into this process. Very frustrating... Thanks for whatever time anyone has on all of this... Keyton On Jan 21, 12:12 am, Martin Conte Mac Donell wrote: > On Wed, Jan 21, 2009 at 2:35 AM, Keyton Weissinger wrote: > > > Oh and just to re-state, this exact same code works like a champ on > > import of School or Parent data (neither of which have a ManyToMany > > field). > > > Keyton > > I can't reproduce this exception. Try to print import_object_dict just > before "new_object = > model_import_info.model_for_import.objects.create(**import_object_dict)". > > > Note that I am NOT yet trying to SAVE the Student object, just instantiate > > it. > > Actually Model.objects.create() do try to save() object. If you don't > want it, call Model(**import_object_dict) > > M. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
Oh and just to re-state, this exact same code works like a champ on import of School or Parent data (neither of which have a ManyToMany field). Keyton On Jan 20, 11:32 pm, Keyton Weissinger wrote: > Hi Malcolm, > > Thanks very much for the quick reply. I'm using this code as part of a > view in which I'm processing an import of data (part of my reusable > django-batchimport app on google code). Here's a dpaste of the main > part of the code:http://dpaste.com/111306/ > > "model_import_info.model_for_import" (from the code) returns the > appropriate model. I've confirmed that it is returning a Student model > in this case (as the call to get at line #3 works just fine). I *am* > reusing this model over and over, btw. However, I have confirmed that > even if I create it anew each time, I get the same behavior. Also, > none of the data I am using actually has a Parent in it (the > ManyToMany field culprit). > > To your point, I've tried it both with explicitly setting the model to > Student and using get_model. Using both methods, it works at > interactive prompt but not in the view. > > Here's a dpaste of the exact stack trace I'm getting:http://dpaste.com/111304/ > > Not to confuse the issue, but looking at the django code from the > dpaste -- at the "setattr(self, field.attname, val)" call (line 38 on > dpaste link) -- the local variables tell me I'm dealing with a > ManyToMany object ( object at 0x2e04c90>). I say that just to rule out some problem with > the School object (a OneToMany) that *IS* being passed in. > > I appreciate any time you have to spend on it very much. > > Best, > Keyton > > On Jan 20, 11:02 pm, Malcolm Tredinnick > wrote: > > > On Tue, 2009-01-20 at 19:32 -0800, Keyton Weissinger wrote: > > > Hello, > > > > OK. I'm totally stuck. I am trying to create an object (of type > > > Student -- see below) with the following: > > > > new_student = Student.objects.create(**import_object_dict) > > > > I'm using the following dictionary as "import_object_dict" above > > > (aside from the name of the school, this is fake data, so no privacy > > > worries): > > > > import_object_dict={'address': u'142, Quilly Lane', 'city': > > > u'Columbus', 'dob': '1956-12-29', 'email': > > > u'miles.l.ye...@spambob.com', 'first_name': u'Yeung', 'phone_primary': > > > u'614-468-5940', 'school': , > > > 'state': u'OH', 'title': u'Mr.', 'type': u'Student', 'zip': 43215.0} > > > > Note that I am NOT yet trying to SAVE the Student object, just > > > instantiate it. > > > > But every time I try to instantiate this new Student, I get the > > > following error: > > > 'Student' instance needs to have a primary key value before a many-to- > > > many relationship can be used. > > > > The Student object DOES have a ManyToMany relationship (with Parent -- > > > see below) but I'm not in any way trying to access it here. > > > > I am using inheritance which may be complicating matters (see models > > > below). > > > > And here's a clue that may help you (but hasn't yet helped me): > > > > When I try this on the command line (using "manage.py shell" and then > > > importing Student, creating a School object, etc) it works just fine. > > > No error. Using the exact same dictionary as above the exact same way. > > > > Also, the code above isn't exactly accurate. I'm actually dynamically > > > getting the model object using get_model. I simplify the question here > > > because I've used the same exact method to create other types of > > > objects (without ManyToMany fields) with no problem whatsoever. > > > Bonus points for a clear problem description, so thanks for doing that. > > Nothing jumps out at me as obviously wrong, unfortunately. > > > You don't mention how you're using this when it fails -- is it part of a > > script or a view or what? In any case, I would try removing the call to > > get_model(). Even if you just test that the model name is what you think > > should return the Student model and then explicitly set the class you're > > creating to be Student, instead of whatever get_model() returns. I > > *hope* that won't make a difference, because get_model() and friends > > give me a nose-bleed (an
Re: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
Hi Malcolm, Thanks very much for the quick reply. I'm using this code as part of a view in which I'm processing an import of data (part of my reusable django-batchimport app on google code). Here's a dpaste of the main part of the code: http://dpaste.com/111306/ "model_import_info.model_for_import" (from the code) returns the appropriate model. I've confirmed that it is returning a Student model in this case (as the call to get at line #3 works just fine). I *am* reusing this model over and over, btw. However, I have confirmed that even if I create it anew each time, I get the same behavior. Also, none of the data I am using actually has a Parent in it (the ManyToMany field culprit). To your point, I've tried it both with explicitly setting the model to Student and using get_model. Using both methods, it works at interactive prompt but not in the view. Here's a dpaste of the exact stack trace I'm getting: http://dpaste.com/111304/ Not to confuse the issue, but looking at the django code from the dpaste -- at the "setattr(self, field.attname, val)" call (line 38 on dpaste link) -- the local variables tell me I'm dealing with a ManyToMany object (). I say that just to rule out some problem with the School object (a OneToMany) that *IS* being passed in. I appreciate any time you have to spend on it very much. Best, Keyton On Jan 20, 11:02 pm, Malcolm Tredinnick wrote: > On Tue, 2009-01-20 at 19:32 -0800, Keyton Weissinger wrote: > > Hello, > > > OK. I'm totally stuck. I am trying to create an object (of type > > Student -- see below) with the following: > > > new_student = Student.objects.create(**import_object_dict) > > > I'm using the following dictionary as "import_object_dict" above > > (aside from the name of the school, this is fake data, so no privacy > > worries): > > > import_object_dict={'address': u'142, Quilly Lane', 'city': > > u'Columbus', 'dob': '1956-12-29', 'email': > > u'miles.l.ye...@spambob.com', 'first_name': u'Yeung', 'phone_primary': > > u'614-468-5940', 'school': , > > 'state': u'OH', 'title': u'Mr.', 'type': u'Student', 'zip': 43215.0} > > > Note that I am NOT yet trying to SAVE the Student object, just > > instantiate it. > > > But every time I try to instantiate this new Student, I get the > > following error: > > 'Student' instance needs to have a primary key value before a many-to- > > many relationship can be used. > > > The Student object DOES have a ManyToMany relationship (with Parent -- > > see below) but I'm not in any way trying to access it here. > > > I am using inheritance which may be complicating matters (see models > > below). > > > And here's a clue that may help you (but hasn't yet helped me): > > > When I try this on the command line (using "manage.py shell" and then > > importing Student, creating a School object, etc) it works just fine. > > No error. Using the exact same dictionary as above the exact same way. > > > Also, the code above isn't exactly accurate. I'm actually dynamically > > getting the model object using get_model. I simplify the question here > > because I've used the same exact method to create other types of > > objects (without ManyToMany fields) with no problem whatsoever. > > Bonus points for a clear problem description, so thanks for doing that. > Nothing jumps out at me as obviously wrong, unfortunately. > > You don't mention how you're using this when it fails -- is it part of a > script or a view or what? In any case, I would try removing the call to > get_model(). Even if you just test that the model name is what you think > should return the Student model and then explicitly set the class you're > creating to be Student, instead of whatever get_model() returns. I > *hope* that won't make a difference, because get_model() and friends > give me a nose-bleed (and James Bennett gets far too much enjoyment out > of watching me fix those bugs), but it would be nice to know one way or > the other. > > Are you using get_model() at the interactive prompt? Does it work there > instead of failing? > > I'll try to make some time later on today to experiment with the code > you've given here and see if I can repeat it (in the middle of something > right now and just rest my brain by answering email, so not able to do > it this minute, sorry). > > Right now, though, it's not obvious what you're doing that is strange. > Which is a shame. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used
Hello, OK. I'm totally stuck. I am trying to create an object (of type Student -- see below) with the following: new_student = Student.objects.create(**import_object_dict) I'm using the following dictionary as "import_object_dict" above (aside from the name of the school, this is fake data, so no privacy worries): import_object_dict={'address': u'142, Quilly Lane', 'city': u'Columbus', 'dob': '1956-12-29', 'email': u'miles.l.ye...@spambob.com', 'first_name': u'Yeung', 'phone_primary': u'614-468-5940', 'school': , 'state': u'OH', 'title': u'Mr.', 'type': u'Student', 'zip': 43215.0} Note that I am NOT yet trying to SAVE the Student object, just instantiate it. But every time I try to instantiate this new Student, I get the following error: 'Student' instance needs to have a primary key value before a many-to- many relationship can be used. The Student object DOES have a ManyToMany relationship (with Parent -- see below) but I'm not in any way trying to access it here. I am using inheritance which may be complicating matters (see models below). And here's a clue that may help you (but hasn't yet helped me): When I try this on the command line (using "manage.py shell" and then importing Student, creating a School object, etc) it works just fine. No error. Using the exact same dictionary as above the exact same way. Also, the code above isn't exactly accurate. I'm actually dynamically getting the model object using get_model. I simplify the question here because I've used the same exact method to create other types of objects (without ManyToMany fields) with no problem whatsoever. Any suggestions would be VERY much appreciated. Thank you. Keyton class Person(models.Model): title = models.CharField("Title", max_length=4, choices=TITLE_CHOICES) first_name = models.CharField("First name", max_length=100) last_name = models.CharField("Last name", max_length=100) address = models.CharField("Home street address", max_length=100) city = models.CharField("City", max_length=100) state = models.CharField("State", choices=STATE_CHOICES, max_length=100) zip = models.CharField("Zipcode", max_length=100) email = models.EmailField("Preferred email address") phone_primary = PhoneNumberField("Primary phone #") phone_secondary = PhoneNumberField("Secondary phone #", blank=True, null=True) invite_key = models.CharField("Last invitation code", max_length=50, blank=True, null=True) invite_datetime = models.DateTimeField("Last invitation date",blank=True, null=True) type = models.CharField("User type", max_length=15, choices=USER_TYPE_CHOICES, blank=True, null=True) school = models.ForeignKey(School, blank=True, null=True) user = models.ForeignKey(User, unique=True, blank=True, null=True) def __unicode__(self): return self.last_name + ', ' + self.first_name def get_absolute_url(self): return ('profiles_profile_detail', (), { 'username': self.user.username }) get_absolute_url = models.permalink(get_absolute_url) def save(self, force_insert=False, force_update=False): if self.user: self.user.email = self.email super(Person, self).save(force_insert, force_update) # Call the "real" save() method. class Parent(Person): pass class Student(Person): dob = models.DateField("Student's birth date", help_text='Used for determining age.') parents = models.ManyToManyField(Parent, related_name="student_parent",blank=True, null=True, ) def __unicode__(self): return self.last_name --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Can I help you import your data into django (for free, of course)?
Hi All. Some of you have checked out django-batchimport to either bulk import or bulk update your database. Some of you have provided some great feedback. Thank you! Seems like it's working fairly well for straightforward XLS files. But I'd like to offer better support for CSV files and more difficult XLS files and I'd just as soon use some real-world test data than something manufactured. So... If you need to get some data imported into your django app but are having trouble with your custom script, etc and you meet the following criteria: * Your data is in CSV or XLS format to start. * Your data is NOT sensitive/private (and small enough to provide it to me). * You don't mind sharing your models.py file. Then let me help get your data imported! You can try either django-batchimport (http://code.google.com/p/django- batchimport/) yourself and let me know how it goes or you can contact me off-list and arrange to get me your data and your models file so I can take a look (though I'll need to use sqlite on my end). If I can get django-batchimport working with your data, I'll update the project and work with you to get it set up with your project so you can use it to do batch imports/updates for your project. Thank you everyone! Keyton --~--~-~--~~~---~--~~ 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: Setting Bound Fields Programmatically
WAIT! Crap. If all else fails, RTFM. I'm sorry everyone. I just re-read the docs at http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ on commit=False. I get it now. Thank you all! K On Jan 8, 7:47 am, Keyton Weissinger wrote: > Thank you both very much for taking the time to respond... > > I got it to work using the following: > if request.method == 'POST': > > my_data = {'type':user_type, > 'school':current_school.id, > 'title': request.POST['title'], > 'first_name': request.POST['first_name'], > 'last_name': request.POST['last_name'], > 'phone_1': request.POST['phone_1'], > 'phone_2': request.POST['phone_2'], > } > #request.POST.update(my_data) > form = form_class(data=my_data, files=request.FILES) > # blah blah blah > > I haven't the foggiest why this worked and the former didn't. They're > just dictionaries for goodness sake. > > Anyway... > > To Karen's (and your) points, I think I may be missing the boat here. > > I have a Teacher class that needs to have a school. I'm setting it > above manually ('school':current_school.id) as I don't want a teacher > setting his/her OWN school (I want to do it based on the admin's > actions etc). > > It seems Karen's suggestion of having school be excluded from the form > (via the class's Meta class) makes sense, but wouldn't that mean I > have to have required=False on the school field in my Teacher object > for it before the form.save will work in such a way as to save the > underlying model? > > Keyton > > On Jan 8, 12:38 am, Malcolm Tredinnick > wrote: > > > On Wed, 2009-01-07 at 21:28 -0800, Keyton Weissinger wrote: > > > I have a form with the following fields (all required): > > > - first_name > > > - last_name > > > - site_id > > > > I'd like to use a template to display only the FIRST two items to the > > > user for him to fill out: > > > > > > > {{ form.first_name }} > > > {{ form.last_name }} > > > > > > > > > > Then when it gets posted back to me I'd like to set the site_id based > > > on a session variable or whatever like this (from my view): > > > > if request.method == 'POST': > > > my_data = {'site_id':1234} > > > my_data.update(request.POST) > > > form = form_class(data=my_data, files=request.FILES) > > > if form.is_valid(): > > > process form here... > > > > My problem is that I cannot get the form to validate. It keeps telling > > > me that site_id is not set. > > > On the surface, that look like it should work. Which makes me suspect > > some important detail has been lost in the simplification. > > > What does the my_data dictionary look like just before you execute the > > "form = ..." line (print it out)? > > > Also, how is form_class specified? Finally, what is the exact error > > Django gives you? Print out form._errors, for example. > > > Maybe somewhere in there the answer will jump out. Admittedly, all the > > clues may already be there and I'm just missing the obvious, but I can't > > see it right now. > > > On a related note, is there any particular reason you need to have > > site_id in the form class at all? Even if it's a model form, you could > > exclude it, and add it into the model object later, couldn't you? You > > might be going about this slightly backwards by trying to force in > > site_id when it's not something that actually needs to be validated or > > form-processed. > > > Regards, > > Malcolm > > --~--~-~--~~~---~--~~ 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: Setting Bound Fields Programmatically
Thank you both very much for taking the time to respond... I got it to work using the following: if request.method == 'POST': my_data = {'type':user_type, 'school':current_school.id, 'title': request.POST['title'], 'first_name': request.POST['first_name'], 'last_name': request.POST['last_name'], 'phone_1': request.POST['phone_1'], 'phone_2': request.POST['phone_2'], } #request.POST.update(my_data) form = form_class(data=my_data, files=request.FILES) # blah blah blah I haven't the foggiest why this worked and the former didn't. They're just dictionaries for goodness sake. Anyway... To Karen's (and your) points, I think I may be missing the boat here. I have a Teacher class that needs to have a school. I'm setting it above manually ('school':current_school.id) as I don't want a teacher setting his/her OWN school (I want to do it based on the admin's actions etc). It seems Karen's suggestion of having school be excluded from the form (via the class's Meta class) makes sense, but wouldn't that mean I have to have required=False on the school field in my Teacher object for it before the form.save will work in such a way as to save the underlying model? Keyton On Jan 8, 12:38 am, Malcolm Tredinnick wrote: > On Wed, 2009-01-07 at 21:28 -0800, Keyton Weissinger wrote: > > I have a form with the following fields (all required): > > - first_name > > - last_name > > - site_id > > > I'd like to use a template to display only the FIRST two items to the > > user for him to fill out: > > > > > {{ form.first_name }} > > {{ form.last_name }} > > > > > > > Then when it gets posted back to me I'd like to set the site_id based > > on a session variable or whatever like this (from my view): > > > if request.method == 'POST': > > my_data = {'site_id':1234} > > my_data.update(request.POST) > > form = form_class(data=my_data, files=request.FILES) > > if form.is_valid(): > > process form here... > > > My problem is that I cannot get the form to validate. It keeps telling > > me that site_id is not set. > > On the surface, that look like it should work. Which makes me suspect > some important detail has been lost in the simplification. > > What does the my_data dictionary look like just before you execute the > "form = ..." line (print it out)? > > Also, how is form_class specified? Finally, what is the exact error > Django gives you? Print out form._errors, for example. > > Maybe somewhere in there the answer will jump out. Admittedly, all the > clues may already be there and I'm just missing the obvious, but I can't > see it right now. > > On a related note, is there any particular reason you need to have > site_id in the form class at all? Even if it's a model form, you could > exclude it, and add it into the model object later, couldn't you? You > might be going about this slightly backwards by trying to force in > site_id when it's not something that actually needs to be validated or > form-processed. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Setting Bound Fields Programmatically
I have a form with the following fields (all required): - first_name - last_name - site_id I'd like to use a template to display only the FIRST two items to the user for him to fill out: {{ form.first_name }} {{ form.last_name }} Then when it gets posted back to me I'd like to set the site_id based on a session variable or whatever like this (from my view): if request.method == 'POST': my_data = {'site_id':1234} my_data.update(request.POST) form = form_class(data=my_data, files=request.FILES) if form.is_valid(): process form here... My problem is that I cannot get the form to validate. It keeps telling me that site_id is not set. How can I programmatically set this one form field's value and have the user set the others without sending through a hidden field yada yada. Please help! Thank you. Keyton --~--~-~--~~~---~--~~ 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: Import models from CSV files?
Hey Victor, I did the django-batchimport mentioned earlier. I think it will address your need but is definitely aimed at XLS. However, it does already handle duplicates (it will either update them or ignore them based on setting). You can also specify a subset of model fields to use to determine whether a given row represents a duplicate. This allows for "batch update" too. If you get into it and have any problems, drop me a note. Keyton On Jan 6, 12:02 am, Victor Hooi wrote: > heya, > > This question might seem a bit simple, but what's the best way to > instantiate models from .csv files? > > Essentially, I have two .csv files. One contains a list of people, and > their access rights (one-to-many). The second .csv file contains a log > of doorway access (just a bunch of sequential lines). I have a simple > python script which imports these two .csv files, does some processing > (the files are quite messy), creates user and access-entry objects, > and produces a reconciliation with a list of exceptions (basically > door entries which aren't in the list of user/access rights). Each > user is just a dictionary, with their username as key, and a tuple of > dictionary objects for their various access rights. > > I would like a simple django project to import these logs, instantiate > models, and then basically manage it via the in-built admin interface, > hopefully saving a lot of time =). (will also need to deal with > duplicates). Is there a smart way to go about doing this project, or > any existing addons I can leverage off? > > Thanks, > Victor --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
RELEASED: django-batchimport 0.1
Greetings All, I've just finished the 0.1 version of django-batchimport and have released it on code.google.com. Go to http://code.google.com/p/django-batchimport/ for more information (and SVN checkout). This application can be added to any django project to give it batch import capability via uploaded Microsoft Excel file (or other formats saved as XLS). This allows for someone with a spreadsheet of, say, users to easily upload it and add it all at once. While batch importing in django is easy to do via fixtures, this reusable app is aimed at being for non-developer end users of your web application. The process by which this app does it's work is completely dynamic, inspecting both the spreadsheet and the django models dynamically at runtime. No prior knowledge of either the model into which the user is importing or the spreadsheet uploaded is required. The only prerequisite is John Machin's xlrd library (http:// www.lexicon.net/sjmachin/xlrd.htm), python 2.5+, and django 1.0+. See the website for full details and please drop me a note on the django-batchimport-users group if you have questions or comments. Thank you. Keyton --~--~-~--~~~---~--~~ 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: Weird Behavior in Template Rendering: First Letter Only ?!?!
Thanks Alex! That was the hint I needed. I ended up going through my dictionary of fields (on my form object) in my view and getting BoundField instances for each. That did the trick. Thank you all! Keyton On Jan 2, 12:57 am, Keyton Weissinger wrote: > OK. I changed the code below to (note .items): > > {% for key, value_list in my_dict.items %} > {{ key }} > {% for item in value_list %} > {{ item }} > {% endfor %} > {% endfor %} > > Now I get the full key value but for each item (which again is a form > field) I get something like this rendered to the HTML: > > > instead of a nicely rendered field. > > Any ideas? > > Thank you! > > Keyton > > On Jan 2, 12:06 am, Keyton Weissinger wrote: > > > I'm passing a dictionary of values that look something like this: > > > {'name1':[field1, field2, field3], 'name2':[field4, field5,field6]..} > > > Each key is a simple string and each value is a list of form fields. > > > I should be able to do something like this in the template to render > > same: > > {% for key, value_list in my_dict %} > > {{ key }} > > {% for item in value_list %} > > {{ item }} > > {% endfor %} > > {% endfor %} > > > or similar. > > > When I do this I get something weird. I only get the first letter of > > the key (so 'n' for my sample keys above) and for each item above > > (remember each item represents a form field and should just render as > > an HTML field/widget/etc) I get only the first letter of the label of > > the form field. > > > I've tried it many different ways and I'm stymied. > > > Has anyone seen anything like this? > > > Thank you! > > > Keyton --~--~-~--~~~---~--~~ 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: Weird Behavior in Template Rendering: First Letter Only ?!?!
OK. I changed the code below to (note .items): {% for key, value_list in my_dict.items %} {{ key }} {% for item in value_list %} {{ item }} {% endfor %} {% endfor %} Now I get the full key value but for each item (which again is a form field) I get something like this rendered to the HTML: instead of a nicely rendered field. Any ideas? Thank you! Keyton On Jan 2, 12:06 am, Keyton Weissinger wrote: > I'm passing a dictionary of values that look something like this: > > {'name1':[field1, field2, field3], 'name2':[field4, field5,field6]..} > > Each key is a simple string and each value is a list of form fields. > > I should be able to do something like this in the template to render > same: > {% for key, value_list in my_dict %} > {{ key }} > {% for item in value_list %} > {{ item }} > {% endfor %} > {% endfor %} > > or similar. > > When I do this I get something weird. I only get the first letter of > the key (so 'n' for my sample keys above) and for each item above > (remember each item represents a form field and should just render as > an HTML field/widget/etc) I get only the first letter of the label of > the form field. > > I've tried it many different ways and I'm stymied. > > Has anyone seen anything like this? > > Thank you! > > Keyton --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Weird Behavior in Template Rendering: First Letter Only ?!?!
I'm passing a dictionary of values that look something like this: {'name1':[field1, field2, field3], 'name2':[field4, field5,field6]..} Each key is a simple string and each value is a list of form fields. I should be able to do something like this in the template to render same: {% for key, value_list in my_dict %} {{ key }} {% for item in value_list %} {{ item }} {% endfor %} {% endfor %} or similar. When I do this I get something weird. I only get the first letter of the key (so 'n' for my sample keys above) and for each item above (remember each item represents a form field and should just render as an HTML field/widget/etc) I get only the first letter of the label of the form field. I've tried it many different ways and I'm stymied. Has anyone seen anything like this? Thank you! Keyton --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Has anyone released a "User-Specific File Manager App?"
Hi There, I have a use case to build an online "file-locker" sort of app where each user can upload and download files (word processing documents, excel spreadsheets, etc) into a user-specific/secure location. Users would log into the site, and see the files on the server in their specific "locker" and download from there or upload to there. Should be pretty straightforward but this, like most projects, could get complex with bells and whistles. So I thought I'd see what was out there. I've seen a couple decent projects out on Google: http://code.google.com/p/django-fileman/ http://code.google.com/p/django-filebrowser/ The first looks good (though in Russian so I'm still figuring out exact suitability) and might work. The second is more for admins (i.e. not for the rank-and-file user of a site). Just wanted to send a query to the community. Anyone know of other open source projects out there that I might start from? Thank you! Keyton --~--~-~--~~~---~--~~ 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: Best IDE for Django and python?
It's unlikely I will be able to add much after Russ, but I will suggest a book that has helped me a GREAT deal in support of the IDE- approach: Foundations of Agile Python Development: http://www.amazon.com/Foundations-Python-Development-Experts-Source/dp/1590599810 It goes step-by-step over subversion and eclipse and pydev. It covers windows and linux though the author uses linux. I was able to use everything on Windows just fine but I HAVE migrated to linux since then (painful but possible)... Good luck and while I'm not much less new than you, I can say with sincerity, WELCOME! Keyton On Nov 25, 5:59 am, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > On Tue, Nov 25, 2008 at 5:27 PM, DragonSlayre <[EMAIL PROTECTED]> wrote: > > > Hey, I'm getting started with a friend in developing a site with > > Django, and we're both new to this, so I am wondering what people use > > to manage all their files, and for looking at documentation etc. > > While I must apologize for Kenneth's poorly expressed frustration, his > underlying message is sound - this has come up _many_ times on > Django-users. A quick Google search should return many options, but > there is no clear or correct answer to your question. > > > Having come from a Java background, I'm used to great documentation, > > and suspect that Java is very much the leader in doc, and not the > > standard. > > Having spent the afternoon wrestling with J2EE, I'd strongly disagree > with this assertion. I will agree that Java projects tend to have have > very extensive API documentation. This is a result of the combination > of Javadoc and strong IDE integration that supports Javadoc. However, > the quality of that documentation is highly variable. Unfortunately, > the fact that Java IDEs automatically write Javadoc stubs and provide > 1 button "build the documentation" hooks gives developers the mistaken > impression that a project is "well documented". Documentation for the > method "get_username()" that reads "Returns the username" doesn't > really illuminate anything. > > There is also the argument that good APIs don't require lots of API > documentation - after all, it should be obvious what get_username() > returns. If your API entry points require extensive explanations, > perhaps you need a better API. > > Good documentation means more than an API (and a _lot_ more than an > empty autogenerated stub). Documentation means good explanations of > the big picture - how the pieces fit together, how to achieve > important tasks, significant internal states, etc. This sort of > documentation doesn't fit well into simple API docs. It is also very > hard to write, and as a result, it often isn't written, and when it > is, it is rarely written well. This isn't unique to Java, either - the > vast majority of open source projects suffer from this affliction. > > I'd like to think that Django is on the better end of the spectrum > when it comes to documentation - we are blessed to have a journalism > major amongst our project founders, and a couple of other liberal arts > majors amongst the frequent contributors. As a result, > docs.djangoproject.com is a pretty thorough resource, and is generally > well written. This documentation is by no means perfect, but it is > certainly better than a lot of other projects out there. > > In addition to the official documentation, there is a wealth of > contributions on django-users and in the blogging community around > Django that provides excellent material to supplement the official > docs. Again, Google is your friend, and Django is a pretty specific > Google keyword :-) > > > I've used the pydev plugin for eclipse, but it seems extremely > > limited. > > I've used PyDev too, and I'd agree with your assessment. However, > others seem to like it. YMMV. > > > How do you develop your django projects, and where do you go when you > > need to find documentation? > > Your original query actually reveals a bias that is significant - why > do you want an IDE in particular? > > Java, as a semi-traditional compiled language, lends itself to IDE > development. The write-compile-run cycle places a certain imperative > on getting code right the first time. Admittedly, the incremental > compilation features of modern Java IDEs make this less of an issue, > but the general language culture leans towards tools and development > techniques that support this general philosophy. > > However, dynamic languages tend not to leverage IDEs as much. A lot of > Python developers (and developers in other dynamic languages) tend to > develop using relatively lightweight text editors. Some of these > editors provide code highlighting, code completion, and other IDE-like > features, but they definitely don't go as far as a traditional IDE. > > There are at least two reasons for this. Firstly, dynamic languages > don't require a write-compile-run cycle, so they lend themselves to > much greater experimentation. Want to know if an idea will work?
Eclipse/Mylyn for Django Dev
This is a question for my fellow Eclipse/PyDev fans Have any of you gone through the trouble to change your work flow to take advantage of Mylyn? >From the Mylyn web page (http://www.eclipse.org/mylyn/): "Mylyn is a task-focused interface for Eclipse that reduces information overload and makes multi-tasking easy." It seems like a really cool idea but I've not bothered to really give it a go for a project (not wanting to take time to retool). So I wanted to see if anyone out there had taken that leap and could comment on their experience. Keyton --~--~-~--~~~---~--~~ 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: Read/Create Excel xls files using django
I've used xlrd. It's pretty straightforward and Excel 2007 is in the works... Here's the main Google Group for both projects: http://groups.google.com/group/python-excel Keyton On Nov 13, 10:44 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > >> [my stuff about using XML templates with Excel] > > Not trying to start a flame war, but pyexcelerator/xlwt support these > > as well... > > No flame-war perceived...just sharing the hack I've used that > doesn't involve much more complexity than a prefab template and > Django's built-in templating. > > [Steve & Matt dialoging] > > >> I think Tim's point is that with XML you can use Excel visually to > >> create the spreadsheet you want, then use Django's existing template > >> mechanism to tailor the output as required. It struck me as a very neat > >> solution to the problem posed. > > > Good point, I didn't catch it on my way through ;) Though I've heard > > of people doing similar XML manipulation after someone (good with > > design) does layout in OpenOffice, and then exporting to (ms) office. > > I don't know if it's easy to reverse engineer the format of more > complex documents -- my aim was merely to reverse enough of the > format to export the data I wanted in a more preserving fashion. > For my simple data-dumps, it was good. For complex > fixed-dimension Excel files, it would also likely serve well (as > a matter of fact, you can just put values like "{{ obj.field }}" > in your cells). But for more complex layouts that also need to > dynamically grow rows or columns, something more domain-specific > like Matt mentions will likely cause less headache. However, MS > does offer reference materials on the format[1] > > > Is the 2K3 xml format supported by other versions of Office? > > I don't know how far back it's readable -- I've got O2k3 on my > office development machine, and others in the office with 02k7 > have no problems opening the export files. I don't have access > to pre-'03 versions for testing. From what I've read, it works > in "Excel 2002" (such a creature exists?) > > -tim > > [1]http://msdn.microsoft.com/en-us/library/aa140066.aspx --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Waiting List App
I need a waiting list application in which a site's functionality hasn't come online yet and I want to gather email addresses of folks interested in hearing when we go live. I know that building such as application would be almost trivial, but in the interest of reuse, I thought I'd ask if anyone knew of one. I've looked on Google for "django waiting list app" and similar to no avail. Probably too easy to consider a reusable app, but, again, I thought I'd ask. Thank you! Keyton --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Pinax on Windows
I'm trying to get Pinax 0.5.0 set up on a windows XP box using Django 1.0. I'm just trying to get the BASIC project setup. No customization. I've executed the Windows-specific warning here: http://pinaxproject.com/docs/0.5.0/install.html I did that and it seems no matter what I've tried (and I've tried a fair bit), I keep getting the following error: Traceback: File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response 77. request.path_info) File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in resolve 178. for pattern in self.urlconf_module.urlpatterns: File "C:\Python25\lib\site-packages\django\core\urlresolvers.py" in _get_urlconf_module 197. self._urlconf_module = __import__(self.urlconf_name, {}, {}, ['']) File "C:\kweissinger\Tools\pinax\projects\basic_project\..\basic_project\urls.py" in 12. url(r'^$', direct_to_template, {"template": "homepage.html"}, name="home"), Exception Type: NameError at / Exception Value: name 'url' is not defined Any one dealt with this? There seems to be some tantalizingly promising hits on Google but I've been looking through them for an hour and can't figure it out. Would love to start digging into Pinax and use it, but I can't seem to get it going. And before anyone chimes in with "Get a real OS", I know I know. It would certainly help in this problem. But that's not an option this afternoon. Thank you in advance! Keyton --~--~-~--~~~---~--~~ 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: Django Equivalent to Rails Rumble
Hi Again Everyone, First my apologies to the group on not explaining what Rails Rumble was. Jeremy posted some details above. Here are some more from the website (http://railsrumble.com/): [About the Contest] The Rails Rumble is a 48 hour web application development competition. As a contestant, you get one weekend to design, develop, and deploy the best web property that you can.. [blah] [blah] [blah] The build portion of this years event took place over the weekend of October 18th and 19th. Voting is now in progress. Winning teams will not only receive kudos from the Ruby on Rails community, they'll also win a number of incredible prizes, supplied by our event sponsors. By participating as a voter, you may also qualify to win a $20 USD Amazon gift voucher (5 winners selected randomly). The reason it's getting attention is that a few of the applications from the 2007 contest actually became startup businesses that have lasted since last year. Here's an article describing the 2008 contest from last week's TechCrunch: http://www.techcrunch.com/2008/10/23/131-web-apps-launched-this-past-weekend-vote-for-the-best/ >From the TechCrunch article: "Around five apps out of 90 total from the 2007 competition are still around today, including last year’s winner Tasty Planner (http:// tastyplanner.com/)." I'd not heard about Django Dash (though -- I promise -- I Googled it, just apparently not well enough). Here are the results of that: http://www.djangodash.com/results/ James, do you know if this is planned for next year? Keyton --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django Equivalent to Rails Rumble
Hello everyone! Long time listener. First time caller Is there an equivalent to the Rails Rumble for the Django community? Shouldn't there be one? What do you think? Keyton --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---