inlineformset delete on empty revisited
http://pastebin.com/f40a3bde9 I found this little snippet on this group and am trying to get it to work on my model, but no luck. I'm using the code pretty much as-is except for two small changes, which are noted by a code comment. I can create new instances of my model using this formset, bit I can't edit existing instances (I haven't gotten to testing whether "deleting by blanking" works yet). When I try to formset.save(), I get this error: 'RouteBaseForm' object has no attribute 'cleaned_data' which is thrown on line 57 on that snippet. For some reason cleaned_data isn't being defined. Anyone care to take a stab at figuring out whats wrong? I don't know enough about the internals of django to get to the bottom of this... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: post_save signal bug
I modified the above _cached_menu method to just create a new object every time (shown below). It only seems to get the links right, a ManyToMay field, after I save it _twice_? Hmmm...how I get the updated many2many table? def _cache_menu(self, menu, xhtml): """ Stores xhtml into the CachedMenuXhtml table where the row's menu matches the menu_obj. """ if menu and xhtml: cm = self.CachedMenuXhtml(menu=menu,xhtml=xhtml) cm.save() --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
post_save signal bug
Hello, I am trying to implement a cache system using the post_save signal. The problem is the code below, a Thread subclass that ends up calling run(), the cache database never runs. It's driving me crazy!!! Is there something going on with the way Django cache's queries which is what I expect? Can I turn this off? This is the Thread subclass code is below. What I am trying to do is implement a staticpages app which is much like flatpages but it adds a menu foreign key to what is basically a flatpage. I am trying to make a cache system whereby when a user saves a link or a menu, the below code rebuilds the XHTML to use in the staticpage Context. Here is a sample run: 1) I am in the admin and change a menu to consist of a title called "Cool Sites 222" and three links 2) post_save runs and here is what is supposed to be saved in the database (a print is called in my code: Menu 2 Cool Sites 222 http://www.google.com/";>Google Inc http://www.microsoft.com";>Microsoft http://www.ryankaskel.com";>Ryan Kaskel http://www.yahoo.com";>Yahoo Homepage If I don't change anything in the menu, eventually it gets the right XHTML and prints it 3) The cached XHTML in the database is never changed and still contains the information from its creation. I think this is a bug because the following this code: def _cache_menu(self, menu, xhtml): """ Stores xhtml into the CachedMenuXhtml table where the row's menu matches the menu_obj. """ if menu and xhtml: cm = self.CachedMenuXhtml.objects.filter(menu__exact=menu) if cm[0]: print cm[0].xhtml cm[0].xhtml = xhtml cm[0].save() print cm[0].xhtml print xhtml else: new_cm = self.CachedMenuXhtml(menu=menu,xhtml=xhtml) new_cm.save() produces... Cool Sites http://www.microsoft.com";>Microsoft http://www.ryankaskel.com";>Ryan Kaskel http://www.yahoo.com";>Yahoo Homepage [11/Jul/2009 05:03:47] "POST /admin/staticpages/menu/2/ HTTP/1.1" 302 0 Cool Sites http://www.microsoft.com";>Microsoft http://www.ryankaskel.com";>Ryan Kaskel http://www.yahoo.com";>Yahoo Homepage Cool Sites 222 http://www.google.com/";>Google Inc http://www.microsoft.com";>Microsoft http://www.ryankaskel.com";>Ryan Kaskel http://www.yahoo.com";>Yahoo Homepage CODE for Thread subclass that post_save signal calls # Signlas for caching of menu XHTML import threading from django.template.loader import get_template from django.template import Context from django.utils.safestring import mark_safe from django.core.exceptions import ObjectDoesNotExist from asqcom.apps.staticpages.settings import STATICPAGE_TEMPLATE, MENU_TEMPLATE from asqcom.apps.staticpages.settings import LINK_TEMPLATE, MENU_CSS_ID class GenerateMenuXhtml(threading.Thread): """ Subclasses a threading.Thread class to generate a menu's XHTML in a separate thread. All Link objects that have this menu associated with it are gathered and combined in an XHTML unordered list. If the sender is of type Link, then all menus associated with that link are iterated through and rebuilt. """ def __init__(self, instance): from asqcom.apps.staticpages.models import Menu, Link, CachedMenuXhtml self.Link = Link self.Menu = Menu self.CachedMenuXhtml = CachedMenuXhtml self.instance = instance self.menus_to_build = [] self.xhtml_for_menus = [] self.menus_for_cache = [] threading.Thread.__init__(self) def _cache_menu(self, menu, xhtml): """ Stores xhtml into the CachedMenuXhtml table where the row's menu matches the menu_obj. """ if menu and xhtml: print menu print xhtml cm = self.CachedMenuXhtml.objects.filter(menu__exact=menu) if cm[0]: cm[0].xhtml = xhtml cm[0].save() else: new_cm = self.CachedMenuXhtml(menu=menu,xhtml=xhtml) new_cm.save() def cache_menus(self): """ Unpacks the menu objects and the XHTML for that menu and iterates through the list calling _cache_menu which does the real work. """ for pair in self.menus_for_cache: self._cache_menu(pair[0],pair[1]) def _generate_xhtml(self, menu): link_tmpl = get_template(LINK_TEMPLATE or 'staticpages/ link_default.html') menu_tmpl = get_template(MENU_TEMPLATE or 'staticpages/ menu_default.html') # Retrieve all links associated with this menu links = menu.links.all().order_by('text') links_strings = [] for link in links: link_ctx = Context({'title': mark_safe(link.title), 'url': mark_safe(link.url),
Re: Design Tools any suggestions?
I use netbeans and there is a UML plugin that you can download and use for free. On Jul 10, 10:43 pm, dartdog wrote: > Starting to noodle out some system design stuff for Django > implementation does anyone have good ideas suggestions for useful > tools to encompass db (model) business logic and presentation > components, flow and how to tie them together. It seems that the most > obvious solution in freeware is dia? It would be nice to be able to > tie the result to lifecycle documentation? > > Thoughts?? Ideas, I'll run them down, with pointers! --~--~-~--~~~---~--~~ 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: Design Tools any suggestions?
dartdog wrote: > > Starting to noodle out some system design stuff for Django > implementation does anyone have good ideas suggestions for useful > tools to encompass db (model) business logic and presentation > components, flow and how to tie them together. It seems that the most > obvious solution in freeware is dia? It would be nice to be able to > tie the result to lifecycle documentation? i use umbrello (UML editor) the class diagram is very helpful for designing the model layer. ideally, the view and templates should be as thin as possible, with very few (if any) architecture-wide design choice. -- Javier --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Design Tools any suggestions?
Starting to noodle out some system design stuff for Django implementation does anyone have good ideas suggestions for useful tools to encompass db (model) business logic and presentation components, flow and how to tie them together. It seems that the most obvious solution in freeware is dia? It would be nice to be able to tie the result to lifecycle documentation? Thoughts?? Ideas, I'll run them down, with pointers! --~--~-~--~~~---~--~~ 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: duplicate primary key problem
Very cool, Rajesh D. Thanks. Mike On Jul 11, 12:31 am, Rajesh D wrote: > On Jul 10, 11:06 am, adelaide_mike > wrote: > > > > > I suspect this is a question more for a PostgreSQL list, but please > > bear with me. > > > In Django 1.0.2 working with PostgreSQL 8.3 I have a model with an > > implied pkey. PostgreSQL syas this: > > > CREATE TABLE wha_property > > ( > > id serial NOT NULL, > > propnum character varying(16) NOT NULL, > > beds integer, > > baths integer, > > rooms integer, > > garage character varying(8), > > frontage integer, > > is_corner boolean, > > street_id integer NOT NULL, > > land_area numeric(10,2), > > year_built integer, > > valuation_nr character varying(16), > > CONSTRAINT wha_property_pkey PRIMARY KEY (id), > > CONSTRAINT wha_property_street_id_fkey FOREIGN KEY (street_id) > > REFERENCES wha_street (id) MATCH SIMPLE > > ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY > > DEFERRED, > > CONSTRAINT wha_property_street_id_key UNIQUE (street_id, propnum) > > > The wha_property table is populated with 500,000 rows from another > > database. There are gaps in the series of used id numbers. > > > If I attempt to insert a new row Django mostly reports an integrity > > violation at wha_property_pkey, though a couple of times with > > different parent rows it has worked. My very newbie view for > > inserting or updating a row is here: > > >http://dpaste.com/65435/ > > > I would be very happy if someone can spot where I have an error. If > > anyone cares to criticise my view, please be gentle. I am new at this > > Django/PostgreSQL magic. > > The sequence for the id column might be out of sync. That would cause > your inserts to pick an id that already exists. > > Try the following command: > > python manage.py sqlsequencereset wha > > That will print out the SQL that you need to run to get your sequences > back in sync with your data. Run that SQL. Then try inserting new data > through your view again. > > -RD --~--~-~--~~~---~--~~ 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: Ajax with JSON-RPC -- new Django handler
According to the jsonrpc 1.1 working draft, the request type and response should be application/json not application/javascript. Even if you handle requests that are in other types for compatibility, you probably want your responses to be the correct type. http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#RequestHeaders -David On Jul 10, 9:21 am, BenW wrote: > I fixed the above problem with URL reversing by refactoring the > JSONRPCService.__call__ method to grab it from the request object. > > def __call__(self, request, extra=None): > > if request.method == "POST": > return HttpResponse(self.process(request), > mimetype="application/javascript") > > url = request.get_full_path() > return HttpResponse(self.get_smd(url), > mimetype="application/javascript") > > This makes more sense since the service url was already defined in the > urlconf, so there's no point in redefining it just so that it can go > in the SMD. > > I also reworked the get_smd() method in JSONRPCServiceBase to take the > url parameter: > > def get_smd(self, url): > > smd = { > "serviceType": "JSON-RPC", > "serviceURL": url, > "methods": [] > } > > import inspect > for method in self.listmethods(): > sig = inspect.getargspec(self.methods[method]) > smd["methods"].append({ > "name": method, > "parameters": [ {"name": val} for val in sig.args if \ > val not in ("self", "request") ] > }) > > return simplejson.dumps(smd) > > It now defines the smd directly rather than it being defined in > __init__ then populated here. I also added a test to remove 'self' > and 'request' from the reported method parameters since those are > internal and having them reported will cause an RPC client that > imports the remote methods into their namespace (as was discussed in > previous post) to throw errors. > > Purely for my own needs, I added an optional param to > JSONRPCServiceBase.__init__: > > def __init__(self, auth_method=None) > self.auth_method = auth_method > > in JSONRPCServiceBase I fixed up process() to call the auth_method (if > it was defined) to determine if the remote client is allowed to call > that method: > > def process(self, request): > > data = simplejson.loads(request.raw_post_data) > id, method, params = data["id"], data["method"], data > ["params"] > > if self.auth_method: > answer = self.auth_method(request, method, params) > try: > answer, message = answer > except TypeError: > message = "not authorized" > > if not answer: > return self.error(id, 100, message) > > ... > > You can use it like so: > > def adminrpc_auth(request, method, params): > > return request.session.user.is_admin > > adminrpc = JSONRPCService(auth_method=adminrpc_auth) > > @jsonremote(adminrpc) > def save_realm(request, realm_obj): > > return realm_obj > > This way if you have a collection of methods that should only be > available to an admin user, you can test that in one place rather than > in every method. The auth_method can optionally return a custom error > message: > > return request.session.user.is_admin, "Admins Only" > > The default is just "not authorized" -- I'll post my complete mods on > the wiki later. > > Any opinions on my modifications are welcome! > > Thanks, > > Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Is it possible to write this with Q package?
Hello, I have some records in MySQL database. Each record has id: Primary Key, autoincrement Type: varchar Price: float Date: dateTime Type can be a "car" or a "truck". There are many records whose Type is "car" or whose Type is "truck". Date has a format of "2009-07-07 20:00:00". This values changes on a hourly basis. Now for each Type ("car" or "truck"), I need to find how its price changes for the last hour vs. the previous hour. For example, assume that it is now 6:00am and the price for "car" is $16,000. Just one hour ago (5:00am) the price for "car" was $16,500. Then the price changes by 16,000 / 16,500 = 0.97. I need this value 0.97. Is it possible to finish this work with Q package? Can anybody give me a hint how to do it? I have studied Q package and related examples however I still feel at loss. Thanks so much. --~--~-~--~~~---~--~~ 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: Automated Functional Testing
Yes, how many times have you followed the practice of: 1. write some new code 2. (re)start dev server and/or update dev database 3. tab over to your browser and click away 4. tab back to terminal to see the traceback when you hit an error With a functional test suite, it becomes sooo much quicker to just do a "./bin/test" and let a computer program do all that clicking work for you, and you can get straight to the error messages and jump right back into bug fixing. However Canoo only allows you to script your test suites in either XML or Groovy. If you want to write your tests in Python, then zope.testbrowser behaves more-or-less the same as Canoo (automated functional black-box browser testing) except you can write your tests in Python. Although it's Python only, I haven't seen anyone develop a Firefox recorder plug-in which would generate zope.testbrowser test suites ... but then that tends to mostly be a hurdle only for new users, after a bit of practice it becomes much more natural and quicker to express browser actions directly from test code. FWIW, zope.testbrowser is pretty quick too, I'm getting: Ran 49 tests with 3 failures and 9 errors in 1.340 seconds. That doesn't account for set-up and teardown times (and I've got failing tests because I haven't yet automated setup/teardown for the functional test suite for the ldap server that app requires). --~--~-~--~~~---~--~~ 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: Error validating the model
On Fri, Jul 10, 2009 at 6:08 PM, Michael wrote: > On Fri, Jul 10, 2009 at 5:54 PM, sjtirtha wrote: > >> Hi, >> >> I have a problem calling manage.py syncdb for my models. >> Here is my models: >> from django.db import models >> from django.contrib.auth.models import User >> >> # Create your models here. >> class DocumentType(models.Model): >> name = models.CharField(max_length=20, unique=True) >> description = models.CharField(max_length=200) >> assignedType = models.ForeignKey('self') >> >> class Category(models.Model): >> name= models.CharField(max_length=20, unique=True) >> type= DocumentType() >> relatedCategories = models.ForeignKey('self', >> related_name='relatedCategories') >> description = models.CharField(max_length=200) >> >> class Document(models.Model): >> type = DocumentType() >> viewed = models.PositiveIntegerField(max_length=7) >> #rating = >> #ranking = >> created_by = User() >> changed_by = User() >> created_at = models.DateTimeField() >> changed_at = models.DateTimeField() >> categories= models.ManyToManyField(Category, >> related_name='categories') #n to m relationship >> assignedDocuments = models.ForeignKey('self', >> related_name='assignedDocuments') >> parentDocument = models.ForeignKey('self', >> related_name='parentDocument')#1 to n relationship >> >> The error that I got is: >> Error: One or more models did not validate: >> common.category: Accessor for field 'relatedCategories' clashes with field >> 'Category.relatedCategories'. Add a related_name argument to the definition >> for 'relatedCategories'. >> common.category: Reverse query name for field 'relatedCategories' clashes >> with field 'Category.relatedCategories'. Add a related_name argument to the >> definition for 'relatedCategories'. >> common.document: Accessor for field 'assignedDocuments' clashes with field >> 'Document.assignedDocuments'. Add a related_name argument to the definition >> for 'assignedDocuments'. >> common.document: Reverse query name for field 'assignedDocuments' clashes >> with field 'Document.assignedDocuments'. Add a related_name argument to the >> definition for 'assignedDocuments'. >> common.document: Accessor for field 'parentDocument' clashes with field >> 'Document.parentDocument'. Add a related_name argument to the definition for >> 'parentDocument'. >> common.document: Reverse query name for field 'parentDocument' clashes >> with field 'Document.parentDocument'. Add a related_name argument to the >> definition for 'parentDocument'. >> >> What is wrong with my model. >> > > You have related name conflicts. Read about it in the docs: > http://docs.djangoproject.com/en/dev/topics/db/models/#be-careful-with-related-name > > Hope that helps, > > Mn > Could help if I look at the links I send out. Any way, you need to specify a unique related_name: http://docs.djangoproject.com/en/dev/ref/models/fields/#foreign-key-arguments this is so you can properly have reverse relations as are described here: http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects Hope that really helps, Mn --~--~-~--~~~---~--~~ 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: TemplateSyntaxError No such column
Problem solved!!! On Jul 10, 5:41 pm, nixon66 wrote: > Getting errors when I try to render a template. Django indicates that > it is a problem in the template and tells me that there is no such > column as "aid.id". There is no column called ID in either my > template, view or model. Any suggestions. I've included the error, > template, my view and model below. Any help would be appreciated. > > The error:http://dpaste.com/hold/65675/ > > The models:http://dpaste.com/65677/ > > The views:http://dpaste.com/65678/ --~--~-~--~~~---~--~~ 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: Error validating the model
On Fri, Jul 10, 2009 at 5:54 PM, sjtirtha wrote: > Hi, > > I have a problem calling manage.py syncdb for my models. > Here is my models: > from django.db import models > from django.contrib.auth.models import User > > # Create your models here. > class DocumentType(models.Model): > name = models.CharField(max_length=20, unique=True) > description = models.CharField(max_length=200) > assignedType = models.ForeignKey('self') > > class Category(models.Model): > name= models.CharField(max_length=20, unique=True) > type= DocumentType() > relatedCategories = models.ForeignKey('self', > related_name='relatedCategories') > description = models.CharField(max_length=200) > > class Document(models.Model): > type = DocumentType() > viewed = models.PositiveIntegerField(max_length=7) > #rating = > #ranking = > created_by = User() > changed_by = User() > created_at = models.DateTimeField() > changed_at = models.DateTimeField() > categories= models.ManyToManyField(Category, > related_name='categories') #n to m relationship > assignedDocuments = models.ForeignKey('self', > related_name='assignedDocuments') > parentDocument = models.ForeignKey('self', > related_name='parentDocument')#1 to n relationship > > The error that I got is: > Error: One or more models did not validate: > common.category: Accessor for field 'relatedCategories' clashes with field > 'Category.relatedCategories'. Add a related_name argument to the definition > for 'relatedCategories'. > common.category: Reverse query name for field 'relatedCategories' clashes > with field 'Category.relatedCategories'. Add a related_name argument to the > definition for 'relatedCategories'. > common.document: Accessor for field 'assignedDocuments' clashes with field > 'Document.assignedDocuments'. Add a related_name argument to the definition > for 'assignedDocuments'. > common.document: Reverse query name for field 'assignedDocuments' clashes > with field 'Document.assignedDocuments'. Add a related_name argument to the > definition for 'assignedDocuments'. > common.document: Accessor for field 'parentDocument' clashes with field > 'Document.parentDocument'. Add a related_name argument to the definition for > 'parentDocument'. > common.document: Reverse query name for field 'parentDocument' clashes with > field 'Document.parentDocument'. Add a related_name argument to the > definition for 'parentDocument'. > > What is wrong with my model. > You have related name conflicts. Read about it in the docs: http://docs.djangoproject.com/en/dev/topics/db/models/#be-careful-with-related-name Hope that helps, Mn --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Error validating the model
Hi, I have a problem calling manage.py syncdb for my models. Here is my models: from django.db import models from django.contrib.auth.models import User # Create your models here. class DocumentType(models.Model): name = models.CharField(max_length=20, unique=True) description = models.CharField(max_length=200) assignedType = models.ForeignKey('self') class Category(models.Model): name= models.CharField(max_length=20, unique=True) type= DocumentType() relatedCategories = models.ForeignKey('self', related_name='relatedCategories') description = models.CharField(max_length=200) class Document(models.Model): type = DocumentType() viewed = models.PositiveIntegerField(max_length=7) #rating = #ranking = created_by = User() changed_by = User() created_at = models.DateTimeField() changed_at = models.DateTimeField() categories= models.ManyToManyField(Category, related_name='categories') #n to m relationship assignedDocuments = models.ForeignKey('self', related_name='assignedDocuments') parentDocument = models.ForeignKey('self', related_name='parentDocument')#1 to n relationship The error that I got is: Error: One or more models did not validate: common.category: Accessor for field 'relatedCategories' clashes with field 'Category.relatedCategories'. Add a related_name argument to the definition for 'relatedCategories'. common.category: Reverse query name for field 'relatedCategories' clashes with field 'Category.relatedCategories'. Add a related_name argument to the definition for 'relatedCategories'. common.document: Accessor for field 'assignedDocuments' clashes with field 'Document.assignedDocuments'. Add a related_name argument to the definition for 'assignedDocuments'. common.document: Reverse query name for field 'assignedDocuments' clashes with field 'Document.assignedDocuments'. Add a related_name argument to the definition for 'assignedDocuments'. common.document: Accessor for field 'parentDocument' clashes with field 'Document.parentDocument'. Add a related_name argument to the definition for 'parentDocument'. common.document: Reverse query name for field 'parentDocument' clashes with field 'Document.parentDocument'. Add a related_name argument to the definition for 'parentDocument'. What is wrong with my model. Regards, Steve --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
TemplateSyntaxError No such column
Getting errors when I try to render a template. Django indicates that it is a problem in the template and tells me that there is no such column as "aid.id". There is no column called ID in either my template, view or model. Any suggestions. I've included the error, template, my view and model below. Any help would be appreciated. The error: http://dpaste.com/hold/65675/ The models: http://dpaste.com/65677/ The views: http://dpaste.com/65678/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Queries for Related Objects wonky
I'm using Django 1.0.2 and having some problems with Related Object queries. For example I have a model called Project with a ForeignKey to a Django User. class Project(models.Model): ... owner = models.ForeignKey(User) ... by the documentation I would expect the following to give me a list of all Users who are owners of projects but it does not. User.objects.filter(project__owner__isnull=False) Instead it's returning a queryset of all users. Anyone have any insight into this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: parsing urls with dot
On Thursday 09 July 2009 05:47:48 am Dids wrote: > > Why not to add dots to your regexp? For example, [\w\d\-\.]+ ? > > I guess my question should have been: How come \. doesn't appear to be > matched in url.py? > That's the problem, it doesn't work. It should. Are you using raw strings? Post the whole urlpattern here, including the failed regexp, so we can give more specific feedback. -- Aaron Maxwell Hilomath - Mobile Web Development http://hilomath.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Manipulating post data before sending?
Thanks, that worked. On Jul 10, 1:44 pm, Jonathan Buchanan wrote: > > I'm making a small app which is kind of like a blog. I have an Entry > > class which has "ForeignKey(User)" as one of its members. I'm using > > ModelForm to generate the form and I'm excluding the User ForeignKey > > because it will just ask for you to pick a user from a drop-down > > list. > > > Where do I tell it that the User ForeignKey should be request.user? > > I've tried using "initial = {'author' : request.user}". That > > generates an "author_id may not be null." Any ideas? > > Use the "commit" argument to the ModelForm's save() method to get a > hold of the resulting model instance without saving it, make any > changes you want to the instance and then call save() on it yourself. > > There's an example of this in the docs: > > http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav... > > Regards, > Jonathan. --~--~-~--~~~---~--~~ 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: Reading data from database tied to another Django project?
On Jul 10, 12:37 pm, Ben Kreeger wrote: > How do I go about accessing that data from P2's database? Do I need to > create a model in P1 and bind it to a certain table in P2's database? > If that's the case, how do I specify access credentials for that > database? Is that in settings.py? If the two projects live in completely separate databases, then there is no easy way to do that (yet -- there's a GSoC project being actively worked on by Alex Gaynor to provide multi-database support in Django) In a similar situation, where both projects had a database on a common mysql server, I managed to do this with a one-line change to the Django mysql backend, which allowed me to specify a table in the model's Meta class as "database.table" -- this only works because MySQL allows you to access tables in one database from a connection to another, as long as your credentials are valid for both. Another (mysql-only, unfortunately) solution is to run mysqlproxy in front of your P2 database, and have it direct requests for P1 tables to the P1 database server. You would have to be careful to avoid any sort of queries that tried to join the tables from the two databases together, though -- avoiding foreign keys from P1 models to P2 models should be enough. Ian --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Creating a model and related models with Inline formsets
Hi, Using the example at http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets , I am able to _edit_ objects belonging a particular model (using modelforms). I have been trying to follow the same pattern for _creating_ new objects using inline formsets, but have been unable to clear my head enough to bring out a working view for this purpose. Using the same example as in the above link, how would I go about creating a new instance of an "Author" model together with its related "Book" objects? Regards, CM --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Reading data from database tied to another Django project?
Here's the situation: I've got two projects, both Django. One is a simple, public-facing website that renders a library of reStructuredText files, as well as a couple of simple forms using the Forms API. The other is a back-end that requires a login from a member of our staff, and contains database tables, forms, the whole bit; it's practical purpose is for tracking equipment in buildings across a college campus. In this second Django project, let's call it P2, I've got a database table of all the buildings on our campus, as well as a database table of all of our equipment, and most pieces of equipment has a barcode number associated with it. In the first Django project, let's call it P1, I've got a form where a patron will fill out information about who they are, what department, they're with, etc., but I need them to choose a specific building, and if available, specify the barcode number of the troublesome equipment. I want to have a dropdown list of all the buildings show up in the form, but all the data is associated with another project; otherwise, I'd just do a forms.ModelChoiceForm. How do I go about accessing that data from P2's database? Do I need to create a model in P1 and bind it to a certain table in P2's database? If that's the case, how do I specify access credentials for that database? Is that in settings.py? --~--~-~--~~~---~--~~ 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: Manipulating post data before sending?
> I'm making a small app which is kind of like a blog. I have an Entry > class which has "ForeignKey(User)" as one of its members. I'm using > ModelForm to generate the form and I'm excluding the User ForeignKey > because it will just ask for you to pick a user from a drop-down > list. > > Where do I tell it that the User ForeignKey should be request.user? > I've tried using "initial = {'author' : request.user}". That > generates an "author_id may not be null." Any ideas? Use the "commit" argument to the ModelForm's save() method to get a hold of the resulting model instance without saving it, make any changes you want to the instance and then call save() on it yourself. There's an example of this in the docs: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method Regards, Jonathan. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Manipulating post data before sending?
I'm making a small app which is kind of like a blog. I have an Entry class which has "ForeignKey(User)" as one of its members. I'm using ModelForm to generate the form and I'm excluding the User ForeignKey because it will just ask for you to pick a user from a drop-down list. Where do I tell it that the User ForeignKey should be request.user? I've tried using "initial = {'author' : request.user}". That generates an "author_id may not be null." Any ideas? --~--~-~--~~~---~--~~ 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: Ajax with JSON-RPC -- new Django handler
I fixed the above problem with URL reversing by refactoring the JSONRPCService.__call__ method to grab it from the request object. def __call__(self, request, extra=None): if request.method == "POST": return HttpResponse(self.process(request), mimetype="application/javascript") url = request.get_full_path() return HttpResponse(self.get_smd(url), mimetype="application/javascript") This makes more sense since the service url was already defined in the urlconf, so there's no point in redefining it just so that it can go in the SMD. I also reworked the get_smd() method in JSONRPCServiceBase to take the url parameter: def get_smd(self, url): smd = { "serviceType": "JSON-RPC", "serviceURL": url, "methods": [] } import inspect for method in self.listmethods(): sig = inspect.getargspec(self.methods[method]) smd["methods"].append({ "name": method, "parameters": [ {"name": val} for val in sig.args if \ val not in ("self", "request") ] }) return simplejson.dumps(smd) It now defines the smd directly rather than it being defined in __init__ then populated here. I also added a test to remove 'self' and 'request' from the reported method parameters since those are internal and having them reported will cause an RPC client that imports the remote methods into their namespace (as was discussed in previous post) to throw errors. Purely for my own needs, I added an optional param to JSONRPCServiceBase.__init__: def __init__(self, auth_method=None) self.auth_method = auth_method in JSONRPCServiceBase I fixed up process() to call the auth_method (if it was defined) to determine if the remote client is allowed to call that method: def process(self, request): data = simplejson.loads(request.raw_post_data) id, method, params = data["id"], data["method"], data ["params"] if self.auth_method: answer = self.auth_method(request, method, params) try: answer, message = answer except TypeError: message = "not authorized" if not answer: return self.error(id, 100, message) ... You can use it like so: def adminrpc_auth(request, method, params): return request.session.user.is_admin adminrpc = JSONRPCService(auth_method=adminrpc_auth) @jsonremote(adminrpc) def save_realm(request, realm_obj): return realm_obj This way if you have a collection of methods that should only be available to an admin user, you can test that in one place rather than in every method. The auth_method can optionally return a custom error message: return request.session.user.is_admin, "Admins Only" The default is just "not authorized" -- I'll post my complete mods on the wiki later. Any opinions on my modifications are welcome! Thanks, Ben --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Multiple Sites with minimal configuration
Hi Adam, > I'm presuming I will use the sites app. However, I don't see how I > can create and set the SITE_ID through the admin (which is necessary > for number 2). > > Would people suggest that I use the RequestSite class from the sites > app which uses the HttpRequest variables? If so, does anybody know of > any best practice examples in urls.py (I'm presuming). I did something similar but I didn't use sites framework. I started using a Middleware that reads the host and define the site based on it. The middleware acts on all urls and I didn't want this, I want only some views to use this funcionallity, then I change from middleware to a decorator applyed on specific views. See an example: def site_publisher(f): """ Get the site based on the host accessing it. """ def newf(request, *args, **kw): domain = request.META['HTTP_HOST'] if domain.startswith('www.'): domain = domain[4:] request.site = get_object_or_404(Site, domain__name=domain) return f(request, *args, **kw) return newf Best regards, -- Michel Sabchuk http://turbosys.com.br/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
sessions and multiple login as same user
My app is used in an office with multiple users logged in and using it simultaneously. Sometimes they may log in as the same user. Is there any reason this should cause interaction between their sessions? I have looked through the session code and see nothing that should prevent these from operating independently, but the users are reporting occasionaly problems. Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: duplicate primary key problem
On Jul 10, 11:06 am, adelaide_mike wrote: > I suspect this is a question more for a PostgreSQL list, but please > bear with me. > > In Django 1.0.2 working with PostgreSQL 8.3 I have a model with an > implied pkey. PostgreSQL syas this: > > CREATE TABLE wha_property > ( > id serial NOT NULL, > propnum character varying(16) NOT NULL, > beds integer, > baths integer, > rooms integer, > garage character varying(8), > frontage integer, > is_corner boolean, > street_id integer NOT NULL, > land_area numeric(10,2), > year_built integer, > valuation_nr character varying(16), > CONSTRAINT wha_property_pkey PRIMARY KEY (id), > CONSTRAINT wha_property_street_id_fkey FOREIGN KEY (street_id) > REFERENCES wha_street (id) MATCH SIMPLE > ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY > DEFERRED, > CONSTRAINT wha_property_street_id_key UNIQUE (street_id, propnum) > > The wha_property table is populated with 500,000 rows from another > database. There are gaps in the series of used id numbers. > > If I attempt to insert a new row Django mostly reports an integrity > violation at wha_property_pkey, though a couple of times with > different parent rows it has worked. My very newbie view for > inserting or updating a row is here: > > http://dpaste.com/65435/ > > I would be very happy if someone can spot where I have an error. If > anyone cares to criticise my view, please be gentle. I am new at this > Django/PostgreSQL magic. The sequence for the id column might be out of sync. That would cause your inserts to pick an id that already exists. Try the following command: python manage.py sqlsequencereset wha That will print out the SQL that you need to run to get your sequences back in sync with your data. Run that SQL. Then try inserting new data through your view again. -RD --~--~-~--~~~---~--~~ 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: ImportError: No module named urls
On Fri, Jul 10, 2009 at 10:33 PM, huw_at1 wrote: > > So I switched from mod_python to mod_wsgi since I don;t really know > what is going on and I realise mod_wsgi is recommended for 1.1 now. > Anyway the rest of my site works fine now. The only part still not > working is the admin section which fails with this "No module named > urls" error as can be seen in the traceback above. > > For my settings I have the root urlconf as "myapp.urls". > > In the urls file I have: > > (r'^admin/(.*)', include('admin.site.urls')), > > as is specified in the latest release notes. That isn't what the release notes say - the new form for the admin includes is: (r'^admin/', include(admin.site.urls)), Note that there is no need for the wildcard regex pattern, and there are no quotes around admin.site.urls - it isn't a string, it's an attribute on the site object. This form was introduced for Django v1.1. However, the old form ( the same as your include('admin.site.root') ) should continue to work. This form has been officially deprecated, but it is guaranteed to work until the release of Django v1.3 (i.e., two full releases in a deprecated state). Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: NameError: name 'Job' is not defined
On Jul 10, 8:39 am, bruno wrote: > Hi, > > I'm new in django and I have problem with importing models > > I have two class : Job and Event > > The Job class defines a method run_job() wich do something and log the > result by creating a new Event so I need to import the Event class > from file app/events/models.py > The Event class reference the job who created the log entry so I need > to import the Job class from file app/jobs/models.py > > file : app/jobs/models.py > -- > > from events.models import Event > ... > > class Job(models.Model): > ... > def run_job(self): > result = do_something() > e = Event(timestamp_gmt=datetime.now(), job=self, > result=result) > self.save() > return result > > file : app/events/models.py > -- > > from jobs.models import Job > ... > > class Event(models.Model): > ... > timestamp_gmt = models.DateTimeField(null=False, editable=False) > job = models.ForeignKey(Job, blank=False, null=False) > > When I start the serveur I have the following error : > ... > File "app\jobs\models.py", line 8, in > from events.models import Event > File "app\events\models.py", line 12, in > class Event(models.Model): > File "app\events\models.py", line 14, in Event > job = models.ForeignKey(Job, blank=False, null=False) > NameError: name 'Job' is not defined > > It's like Django doesn't like the cross import between Job and Event. > Anyone can tell me what I'm doing wrong ? > I think the easy solution is to declar the Event class in the Job > model file but I'd like to keep them in different files. You could move the Event import to the run_job method which is the only place where your code needs it: file : app/jobs/models.py -- class Job(models.Model): ... def run_job(self): from events.models import Event result = do_something() e = Event(timestamp_gmt=datetime.now(), job=self, result=result) self.save() return result -RD --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
duplicate primary key problem
I suspect this is a question more for a PostgreSQL list, but please bear with me. In Django 1.0.2 working with PostgreSQL 8.3 I have a model with an implied pkey. PostgreSQL syas this: CREATE TABLE wha_property ( id serial NOT NULL, propnum character varying(16) NOT NULL, beds integer, baths integer, rooms integer, garage character varying(8), frontage integer, is_corner boolean, street_id integer NOT NULL, land_area numeric(10,2), year_built integer, valuation_nr character varying(16), CONSTRAINT wha_property_pkey PRIMARY KEY (id), CONSTRAINT wha_property_street_id_fkey FOREIGN KEY (street_id) REFERENCES wha_street (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED, CONSTRAINT wha_property_street_id_key UNIQUE (street_id, propnum) The wha_property table is populated with 500,000 rows from another database. There are gaps in the series of used id numbers. If I attempt to insert a new row Django mostly reports an integrity violation at wha_property_pkey, though a couple of times with different parent rows it has worked. My very newbie view for inserting or updating a row is here: http://dpaste.com/65435/ I would be very happy if someone can spot where I have an error. If anyone cares to criticise my view, please be gentle. I am new at this Django/PostgreSQL magic. Regards and thanks for past help. Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Multiple Sites with minimal configuration
I'm creating a new project with pretty simple requirements: 1. A core set of methods for validating data which I will build. 2. The ability for a person with minimal skills to drop HTML form pages (2 or 3) for a given hostname (www.example1.com, www.example2.com, www.example3.com) that accept these variables. There will be dozens of hosts created every year. I'm presuming I will use the sites app. However, I don't see how I can create and set the SITE_ID through the admin (which is necessary for number 2). Would people suggest that I use the RequestSite class from the sites app which uses the HttpRequest variables? If so, does anybody know of any best practice examples in urls.py (I'm presuming). Thanks, Adam --~--~-~--~~~---~--~~ 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: Report Failures when running Django's unit tests?
On Fri, Jul 10, 2009 at 10:41 AM, Eric Brian wrote: > > Ok, so I finally got Django's unit tests to run and when I did, there > was one failure. I checked the FAQ to see if this should be reported > or not. There was no mention, so I wonder, should I report any test > that doesn't pass? > Hard to say without more information. What is the failure, exactly? It might be already covered by an already open ticket. Karen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Report Failures when running Django's unit tests?
Ok, so I finally got Django's unit tests to run and when I did, there was one failure. I checked the FAQ to see if this should be reported or not. There was no mention, so I wonder, should I report any test that doesn't pass? --~--~-~--~~~---~--~~ 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: ImportError: No module named urls
So I switched from mod_python to mod_wsgi since I don;t really know what is going on and I realise mod_wsgi is recommended for 1.1 now. Anyway the rest of my site works fine now. The only part still not working is the admin section which fails with this "No module named urls" error as can be seen in the traceback above. For my settings I have the root urlconf as "myapp.urls". In the urls file I have: (r'^admin/(.*)', include('admin.site.urls')), as is specified in the latest release notes. Although googling around it is confusing as to whether this should be used or: (r'^admin/(.*)', include('admin.site.root')), should be used. Also I'm not sure if I should substitute "site" for "myapp" in here. Again I have found a couple of threads where someone has experienced something similar better exaclty the same as what I am experiencing. Any further suggestions? Many thanks On Jul 9, 5:44 pm, huw_at1 wrote: > Hmm I didn't change any imports as far as i am aware. > > By full traceback do you mean the entirety of the error in the error > log? > > Such as: > > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] mod_python > (pid=26734, interpreter='ccprod.arrowt.co.uk', phase='PythonHandler', > handler='django.core.handlers.modpython'): Application error > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] ServerName: > 'ccprod.arrowt.co.uk' > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] DocumentRoot: > '/var/www' > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] URI: '/admin' > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] Location: '/' > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] Directory: > None > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] Filename: '/ > var/www/admin' > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] PathInfo: '' > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] Traceback > (most recent call last): > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/mod_python/importer.py", line 1542, in > HandlerDispatch\n default=default_handler, arg=req, > silent=hlist.silent) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/mod_python/importer.py", line 1234, in > _process_target\n result = _execute_target(config, req, object, > arg) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/mod_python/importer.py", line 1133, in > _execute_target\n result = object(arg) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/core/handlers/modpython.py", line > 228, in handler\n return ModPythonHandler()(req) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/core/handlers/modpython.py", line > 201, in __call__\n response = self.get_response(request) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/core/handlers/base.py", line 73, in > get_response\n response = middleware_method(request) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/middleware/common.py", line 57, in > process_request\n _is_valid_path("%s/" % request.path_info)): > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/middleware/common.py", line 142, in > _is_valid_path\n urlresolvers.resolve(path) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/core/urlresolvers.py", line 262, in > resolve\n return get_resolver(urlconf).resolve(path) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/core/urlresolvers.py", line 186, in > resolve\n sub_match = pattern.resolve(new_path) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/core/urlresolvers.py", line 184, in > resolve\n for pattern in self.url_patterns: > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/core/urlresolvers.py", line 213, in > _get_url_patterns\n patterns = getattr(self.urlconf_module, > "urlpatterns", self.urlconf_module) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/core/urlresolvers.py", line 208, in > _get_urlconf_module\n self._urlconf_module = import_module > (self.urlconf_name) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] File "/usr/ > lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in > import_module\n __import__(name) > [Thu Jul 09 16:24:08 2009] [error] [client 192.168.2.20] ImportError: > No module named urls > > On 9 July, 16:59, Friðrik Már Jónsson wrote: > > > Hey!
attrs for all choices in choicefield
Hi I have that choice field: RATES = ( ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ) rating = forms.ChoiceField(widget=forms.RadioSelect(), required=True, choices=RATES) Now - how to assign attrs for all choices(for example apply css class for all choices) (i *don't* mean: 'rating = forms.ChoiceField(widget=forms.RadioSelect (attrs={'class':'my_lcass'}), required=True, choices=RATES)' ) --~--~-~--~~~---~--~~ 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: NameError: name 'Job' is not defined
On Fri, Jul 10, 2009 at 9:39 AM, bruno wrote: > > Hi, > > I'm new in django and I have problem with importing models > > I have two class : Job and Event > > The Job class defines a method run_job() wich do something and log the > result by creating a new Event so I need to import the Event class > from file app/events/models.py > The Event class reference the job who created the log entry so I need > to import the Job class from file app/jobs/models.py > > > [...] > > When I start the serveur I have the following error : > ... > File "app\jobs\models.py", line 8, in > from events.models import Event > File "app\events\models.py", line 12, in > class Event(models.Model): > File "app\events\models.py", line 14, in Event > job = models.ForeignKey(Job, blank=False, null=False) > NameError: name 'Job' is not defined > > It's like Django doesn't like the cross import between Job and Event. > Anyone can tell me what I'm doing wrong ? > I think the easy solution is to declar the Event class in the Job > model file but I'd like to keep them in different files. One solution to this is described in the relevant documentation: http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey -- Ramiro Morales http://rmorales.net PyCon 2009 Argentina - Vie 4 y Sab 5 Septiembre Buenos Aires, Argentina http://ar.pycon.org/2009/about/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
NameError: name 'Job' is not defined
Hi, I'm new in django and I have problem with importing models I have two class : Job and Event The Job class defines a method run_job() wich do something and log the result by creating a new Event so I need to import the Event class from file app/events/models.py The Event class reference the job who created the log entry so I need to import the Job class from file app/jobs/models.py file : app/jobs/models.py -- from events.models import Event ... class Job(models.Model): ... def run_job(self): result = do_something() e = Event(timestamp_gmt=datetime.now(), job=self, result=result) self.save() return result file : app/events/models.py -- from jobs.models import Job ... class Event(models.Model): ... timestamp_gmt = models.DateTimeField(null=False, editable=False) job = models.ForeignKey(Job, blank=False, null=False) When I start the serveur I have the following error : ... File "app\jobs\models.py", line 8, in from events.models import Event File "app\events\models.py", line 12, in class Event(models.Model): File "app\events\models.py", line 14, in Event job = models.ForeignKey(Job, blank=False, null=False) NameError: name 'Job' is not defined It's like Django doesn't like the cross import between Job and Event. Anyone can tell me what I'm doing wrong ? I think the easy solution is to declar the Event class in the Job model file but I'd like to keep them in different files. Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 -~--~~~~--~~--~--~---
Adding a custom field to an admin model (table)
Hi, I would like to add a custom field to an existing admin model, namely LogEntry. The goal is to add a comment field, where custom change comments can be added in the admin whenever a model is saved. Is it even possible to add such a field without changing the existing admin codebase? Or would have to define a new model and just override all the admin's *log* methods to save the log msgs to the new model? Any hints how this could be done? Or are the any apps that do similar things, where I could take a look at? Thanks. _ Windows Live™: Keep your life in sync. Check it out! http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009 --~--~-~--~~~---~--~~ 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: more formset adventures
On Fri, Jul 10, 2009 at 7:30 AM, Michael Stevens wrote: > > Hi. > > I'm using a ModelFormset created with lineformset_factory. > > When I click delete on one of the records and save the formset, it > successfully removes the associated db record, but if I redisplay the > formset after the save, it's still showing the now removed form. > > I've modified my code to recreate the formset from the db immediately > after the save: > > if foo_formset.is_valid(): >foo_formset.save() >foo_formset = FooInlineFormset(instance=bar, prefix='foo') > > and it does what I expect, but shouldn't it be in the right state > after the save? > > Looking at the code I think the problem is that BaseModelFormSet > doesn't do anything with deleted forms after it deletes the underlying > model object - I'm expecting them to be removed from the formset as > well. > > I'm running a svn checkout of 1.1. > > Is this a bug, or are my expectations dodgy? :) > The usual pattern for form handling ( http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view) uses an HttpRedirect at the end of the is_valid() leg of handling POST data. So generally when you have successfully performed some action requested in a form, you are not expected to be re-displaying the form that triggered that action. Thus I think your expectations are off. Doing work to make the form "correctly" re-display after a .save() would be a waste of cycles in the normal case. This pattern is not Django-specific. It is a general web application pattern that avoids duplicate POSTs resulting form a user reloading a page and confusing alert boxes when a user tried to reload a page resulting from a POST. Karen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Running the site
Hi Friends... I am new to Django.I Just learning the django now. http://in.pycon.org/2009/ . That website uses django and the code is here - http://bitbucket.org/lawgon/fossconf/downloads/ In this Source code I din't find the models.py to run the Local Server.In what way can i run this package in my local system. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
more formset adventures
Hi. I'm using a ModelFormset created with lineformset_factory. When I click delete on one of the records and save the formset, it successfully removes the associated db record, but if I redisplay the formset after the save, it's still showing the now removed form. I've modified my code to recreate the formset from the db immediately after the save: if foo_formset.is_valid(): foo_formset.save() foo_formset = FooInlineFormset(instance=bar, prefix='foo') and it does what I expect, but shouldn't it be in the right state after the save? Looking at the code I think the problem is that BaseModelFormSet doesn't do anything with deleted forms after it deletes the underlying model object - I'm expecting them to be removed from the formset as well. I'm running a svn checkout of 1.1. Is this a bug, or are my expectations dodgy? :) Michael --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to execute more code after sending an HTTP response in a viewfunction?
On Thu, 2009-07-09 at 13:19 -0700, Fluoborate wrote: > Hello All, > > I am afraid that I might have to write my own middleware to do this. I > really want to do something like the following: > > #In views.py: > > def welcome( request ): > return HttpResponse( "Welcome to my website" ) > #No code after the 'return' statement will ever be executed, but I > wish it would: > time-consuming_function( request ) > > Why do I want to do this? My website feels a bit slow to use, because > it needs to do time-consuming_function. The content of the HTTP > response does not depend on time-consuming_function, so why should the > user have to wait for it? Unfortunately, time-consuming_function DOES > depend on the HttpRequest object and other local variables only > available in the scope of the view function, so it is much more > convenient to execute time-consuming_function inside the view > function. > > Here is how I could do it in middleware, if nobody has an easier > solution: > > @this_view_function_has_a_callback > def welcome( request ): > return HttpResponse( "Welcome to my website" ), time- > consuming_function, { "request" : request } > > I would have to write middleware to unpack the tuple returned by the > view function and do the proper stuff with each piece. What a hassle. > > Has anyone already written that? Is there some much smarter and more > graceful work-around? Thank you all so much. Would doing the expensive function in a generator be enough? Eg: def welcome(request): def worker(): yield "Welcome to my website" yield time_consuming_function(request) return HttpResponse(worker()) The user will see the 'Welcome to my website' immediately, and the page will continue to load in the background, performing your time consuming function. Cheers Tom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to execute more code after sending an HTTP response in a viewfunction?
Kicking off threads could be a solution, if you want your time- consuming_function to run in the same process(es) as django. Otherwise, you'll need to either create new processes or use some inter process communication solution (socket, http, message queue, ...) In the first situation, make sure you that you either don't access the database via the django ORM, or manage the db connection yourself. Django closes db connection when the HTTP Response is returned, using signals. If you play with the db after the request/response cycle has completed, django will be unaware of your db connections and won't close them. Rodrigue On Jul 9, 9:59 pm, Javier Guerra wrote: > On Thu, Jul 9, 2009 at 3:30 PM, Javier Guerra wrote: > > maybe is it possible to use signals like this? i haven't checked the > > source, but it seems plausible to have them dispatched _after_ the > > request is serviced. > > no, it doesn't work like that. also, it seems that a custom > middleware wouldn't work, given the way the WSGIHandler() is written > (the last thing it does is to return the response content). > > go the message queue way. > > -- > Javier --~--~-~--~~~---~--~~ 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: problems with model formsets
I worked it out in the end - I had two formsets in the same form, and hadn't realised the need for the prefix option to separate them. 2009/7/10 Karen Tracey : > On Thu, Jul 9, 2009 at 12:01 PM, Michael Stevens > wrote: >> >> Hi. >> >> I'm trying to use a model formset. >> >> I've successfully got it rendering data from the database and showing >> it on a form to edit, but I'm now trying to recreate the data in save. >> >> So I've got: >> FooFormset = modelformset_factory(Foo exclude = ['id', 'foo']) >> foo_formset = FooFormset(request.POST, request.FILES, >> queryset=Foo.objects.filter(...)) >> >> Without the "request.POST", it works, with the request.POST I get: >> >> Environment: >> >> Request Method: POST >> Request URL: ... >> Django Version: 1.0.2 final >> Python Version: 2.3.4 >> Installed Applications: >> [...) >> Installed Middleware: >> ('django.middleware.common.CommonMiddleware', >> 'django.contrib.sessions.middleware.SessionMiddleware', >> 'django.contrib.auth.middleware.AuthenticationMiddleware') >> >> >> Traceback: >> File "/opt/dev/python/modules/django/core/handlers/base.py" in >> get_response >> 86. response = callback(request, *callback_args, >> **callback_kwargs) >> File "/opt/dev/python/django/.../manager/views.py" in smartad_edit >> 39. foo_formset = FooFormSet(request.POST, request.FILES, >> queryset=Foo.objects.filter(...)) >> File "/opt/dev/python/modules/django/forms/models.py" in __init__ >> 352. super(BaseModelFormSet, self).__init__(**defaults) >> File "/opt/dev/python/modules/django/forms/formsets.py" in __init__ >> 67. self._construct_forms() >> File "/opt/dev/python/modules/django/forms/formsets.py" in >> _construct_forms >> 76. self.forms.append(self._construct_form(i)) >> File "/opt/dev/python/modules/django/forms/models.py" in _construct_form >> 356. kwargs['instance'] = self.get_queryset()[i] >> File "/opt/dev/python/modules/django/db/models/query.py" in __getitem__ >> 221. return self._result_cache[k] >> >> Exception Type: IndexError at /... >> Exception Value: list index out of range >> >> I've censored the stack trace a little to remove anything too sensitive. >> >> What am I doing wrong? > > Are you passing the same queryset in when you create the form for POST as > you did for GET? Without actually looking at the code I think what is > happening here is you have data for more items in the POST dictionary than > you have in your passed queryset. > > Karen > > > > --~--~-~--~~~---~--~~ 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: Some post_related_objects_save signal or workaround?
Thanks for your reply, Ryan, but it would be equivalent to simply calling the self.parent.some_method() from the round save. And my purpose is to have the signal (or other way of tracking) for the point when _all_ objects (rounds) related to the specific object (game) are saved. Something like admin_form.post_m2m_save Also notice that this "fixing ordering" method should change all rounds related to the current game, thus calling their save methods, which would lead to cyclic calls between save methods of the game and the round if the game.save is called from the round.save. Maybe this cycle will always exist and I have to define separate "freeze" method that will be called before the game begin (consequent ordering is required only during the game process), or I should extend the models to work with arbitrary ordering numbers. On Jul 9, 9:07 pm, Ryan K wrote: > Is there any reason you can't create your own signal and put it in the > rounds save() method and then just call the parents save? > > http://docs.djangoproject.com/en/dev/topics/signals/#defining-and-sen... > > Cheers, > Ryan > > On Jul 9, 6:12 am, Eugene Mirotin wrote: > > > Hello! > > > I have a tricky (as seems to me :) problem. > > > Consider I have 2 simply related models - a Game and a Round (with FK > > to Game). Each has some generic fields like name and description. > > Also, the Round has the ordering field (called number) (oh, I can > > imagine your sighs =) > > They are edited on the single admin page for Game with TabularInline > > for game rounds. > > > I know about the way to use jQuery for inlines reordering, but this is > > not the question. Currently I am exactly interested in the manual > > number field filling. > > > So what happens when I save the game? First, the game itself is saved > > because of the need of the saved FK object for rounds saving, and I > > understand it. Then the rounds are saved in order. > > At this point due to some reason the rounds' numbers might be any > > numbers. But my applications requires them to be exactly the > > consequent positive integers starting from 1. > > > This could be easily fixed by a simple loop, but it should be done at > > the appropriate point - on the per-game basis and _after_ all the > > related objects are saved (otherwise nasty bugs with incorrect > > ordering are possible). > > > So I have to know the moment when all the current game's related > > objects are saved. And there is no appropriate standard signal for > > this. > > Any thoughts? > > > Gene --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---