IntegrityErrors after Postgres database restore attempt
Hi folks-- I recently hosed my django database, & attempted to do a restore using Navicat for Postgresql. Seems like this was not the thing to try, as django now throws these: IntegrityError: duplicate key violates unique constraint "django_content_type_pkey" (for instance, after adding a new app & running syncdb) ...anytime I try to add a row to many of the tables (but seemingly not all) which were restored in that fashion. I managed to get the auth_* tables back up to snuff simply by running "manage.py reset auth", then manually re-entering the data (luckily there weren't many items). The big problem now, as you can see from the above error, is that if I try to add a new app, it squawks presumably because it's trying to assign an already existing pkey to django_content_type. The sequencereset command looked promising, but that applies to apps only-- resetting the django_content_type table is what I guess I need to do...? Was thinking of trying dumping the data & running a syncdb-- but I don't know if the django_* tables are necessarily going to be recreated correctly simply by doing that. Hope I'm being clear, & any advice much appreciated! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Switching from soc2009/multidb to trunk; cross db foreign keys
On Thu, Dec 31, 2009 at 12:25 PM, CB wrote: >> In short, you can't (or shouldn't). >> >> What you're asking the database to do is keep a foreign key value that >> is not valid on the database on which it is stored. > > Yes, this is true. > > >> The multi-db branch had checks for this sort of referential integrity >> until just before the merge; however, these checks were relaxed just >> prior to commit in order to allow for multi-db to support master-slave >> partitioning - in these situations, a model will appear to be on a >> different database alias, but won't be a referential integrity failure >> since it is actually the same database. > > Yeah, i watched these checks go up and then drop out. > >> We may also need to look at ways of storing >> cross-database foreign keys to accommodate the sort of use case that >> you describe. > > What about creating a new set of ForeignKey fields that don't actually > do any real foreign key checking? Maybe CrossDBForeignKey, or > RelaxedKey? I suspect something like this will ultimately form part of the solution. There are potentially two types of 'relaxed' FK required - * A FK when you know that the source data always comes from another specific database (e.g. User objects are only on the 'auth' database) * A FK that could point to one of many databases (e.g., Users are spread across multiple databases based on some sharding strategy). Analogous fields will need to exist for M2M fields. > I understand if this is off the timetable for 1.2 (as I can see the > dev group is getting ready for freeze, etc) but if I wanted to develop > this route, do you have any pointers? Might I be able to simply > subclass ForeignKey (or one of it's bases, etc), and more or less lie > about the constraint being fulfilled, tell the DB that this is just an > int (like IntegerField), and then convince the Query internals to ask > for my data seperately (making it not eligible for select_related, for > example)? I haven't tried this myself, but subclassing ForeignKey certainly seems like a reasonable starting point. One complication will be the SQL that is generated; essentially, you need the field to be a FK, but *not* generate field constraints. It *might* be easier to start by subclassing IntegerField, and then introduce an FK-compatible API that accommodates the remote data source. > Either way, i'm going to look into this use case myself and try to > make it work (in a hopefully not /too/ hacky way) . If you or anyone > else has any pointers, please let me know. At this point, you have pretty much all the pointers that I personally have to offer. I'm certainly interested to hear from anyone else on this topic. If you manage to get this working, it would be helpful to hear about any problems you experience. If we're going to put these user-facing features into trunk in the 1.3 timeframe, it would be helpful to have pointers/hints/experiences from people who have actually used multi-db in real-world situations. To that end - if you find that there is a need to modify the core in some subtle way (for example, adding a flag/option to disable select_related), feel free to suggest it. Depending on the proposal, it might not even be out-of-bounds for 1.2. If you can make the case for a generally transparent change to API that will make multi-db practical for a particular use case, it might be covered as a bug fix, and therefore be an acceptable checkin right up until the RC freeze. 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Switching from soc2009/multidb to trunk; cross db foreign keys
> In short, you can't (or shouldn't). > > What you're asking the database to do is keep a foreign key value that > is not valid on the database on which it is stored. Yes, this is true. > The multi-db branch had checks for this sort of referential integrity > until just before the merge; however, these checks were relaxed just > prior to commit in order to allow for multi-db to support master-slave > partitioning - in these situations, a model will appear to be on a > different database alias, but won't be a referential integrity failure > since it is actually the same database. Yeah, i watched these checks go up and then drop out. > We may also need to look at ways of storing > cross-database foreign keys to accommodate the sort of use case that > you describe. What about creating a new set of ForeignKey fields that don't actually do any real foreign key checking? Maybe CrossDBForeignKey, or RelaxedKey? I understand if this is off the timetable for 1.2 (as I can see the dev group is getting ready for freeze, etc) but if I wanted to develop this route, do you have any pointers? Might I be able to simply subclass ForeignKey (or one of it's bases, etc), and more or less lie about the constraint being fulfilled, tell the DB that this is just an int (like IntegerField), and then convince the Query internals to ask for my data seperately (making it not eligible for select_related, for example)? Either way, i'm going to look into this use case myself and try to make it work (in a hopefully not /too/ hacky way) . If you or anyone else has any pointers, please let me know. Thanks, -CB -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Minneapolis Hackathon Jan. 9 using Django for "Neighborly" tool/site
In the Twin Cities? Interested in helping build a tool to connect nearest neighbors online to build community life? For context see: http://pages.e-democracy.org/Neighborly http://pages.e-democracy.org/Hackathon And this invite to our next Hackathon. Cheers, Steven Clift, E-Democracy.org From: Ian Bicking Date: Wed, Dec 30, 2009 at 12:39 PM Subject: Re: [Neighborly] Next Hackathon in January To: neighbo...@forums.e-democracy.org OK, some details for the next hackathon: Date: Saturday, January 9th Time (tentatively): 2pm until we lose steam. Does that sound good? Location: my place, 3015 10th Ave S (map: http://bit.ly/3015-map), Apt. 2 (left door) Please RSVP (just email me i...@colorstudy.com ) to give me an idea of how many people to expect; but if you forget to RSVP don't let that stop you from coming. Bringing drinks and snacks is appreciated, but don't feel obliged. Before the hackathon: Check out the repository: http://github.com/ianb/neighborly Sign up for an account on github. We're full of trust, so everyone gets push access to the main repository. Try to get Postgres and PostGIS installed on your laptop (if you get stuck someone can surely help you at the hackathon, but it's helpful if you try it out ahead of time). Read the README, some of the mail on this list, ask questions, etc. If you can get the code running, that would be great; it doesn't *do* much right now (the only thing it really does is have some models and the standard Django admin forms). In terms of platform, we've got a skeleton built on Django ( http://www.djangoproject.com/) and GeoDjango (http://geodjango.org/). Reading up on those certainly can't hurt. There's interest in using other platforms (e.g., Ruby), though we haven't talked in depth about how that might work. The most obvious way would be things like a scraper that monitors sites of local interest (e.g., the city website) and finds items of local interest, and then adds them to the system (as kind of generic "interesting local content"). Besides programming, these skills are useful: 1. UI work; HTML, etc. 2. Graphic design help is always awesome and usually missing. 3. Helping build up functional documentation; what are we making, how should it work? (for developer consumption) 4. Site documentation (for user consumption) You've probably noticed Steven has already been doing stuff for 3; if we're all on the same page about what we're trying to build I think we'll be much more efficient, so this is really helpful. Anyone with knowledge of HTML can be immediately helpful by building HTML mockups, wireframes, etc; I think it actually works really well to do this frontend work before implementing the programming behind those forms, so -- Ian Bicking | http://blog.ianbicking.org | http://topplabs.org/civichacker Ian Bicking Powderhorn, Minneapolis Info about Ian Bicking: http://forums.e-democracy.org/p/NJlZooDfpAWbJl2mq1oUW -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Totally confused on categorized feeds
I've been following along James Bennett's Practical Django Projects and I'm confused on how to render a template with the correct url that maps to the urlconf for categorized feeds. I understand that the url needs to be in the form feeds/categories/audio but how do I build this url in the template without hard coding it? I've tried the following: urlconf: feeds = { 'entries': LatestEntriesFeed, 'links': LatestLinksFeed, 'categories': CategoryFeed, 'tweets': LatestTweetsFeed } (r'^feeds/categories/(?P.*)/$', 'django.contrib.syndication.views.feed', { 'feed_dict': feeds }, 'category_feed'), in the template: {{ category.title }} which yields: Slug u'audio' isn't registered. -- because categories needs to be passed in to ...and (r'^feeds/(?P.*)/$', 'django.contrib.syndication.views.feed', { 'feed_dict': feeds }, 'category_feed'), which results in a malformed url: /feeds//categories/audio// Thanks for any help, J -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Project optimisation stage: Advice to boost speed of database queries across tables?
Thanks for the replies. Yes, there is the option of going to raw MySQL. However the project requirements mean i can't use raw SQL. (portability, readability) >From what i can see using django's db API i have to execute the queries 500 times. I am very familiar with the query documentation and i know that select_related will prevent foward facing foreign keys translating to an individual sql queries which hit the db and would slow it down. Fact is even when i dont use 'select_related' the major performance problem occurs with the 'many-to-many' and 'reverse foreign' keys (some 75% of the performance penalty for my package method is with these) and only 20% can be solved by select_related. To be specific about how the multiplicities unfold: search_querySet is a Directory.objects.filter(... for s in search_querySet: address_info = s.address_set.all() #.select_related(depth=2) - yes i can/will put select related here but it really does not help that much 20% tops #address_info is usually 2-3 rows from an address table for a in address_info:#.select_related(depth=2): if a.addresstype.adrtype == 'Physical' and a.addradmin.addr_enabled == True: #further reduction in the number of rows which we need to get values from. related_phone=a.phone_set.all() related_email=s.email_set.all() #phones and emails are a small number of rows 2-3 tops It is these lines which produce the performance hit. I cant see a way of using django's query language to avoid having to descend into each of the 500 'directory' objects because of the necessity to get all rows from the related tables in phones an emails and to inspect the type of 'address' object. thanks for the ideas. will continue testing and looking for answers -Sam On Thu, Dec 31, 2009 at 2:41 AM, Nick Arnett wrote: > > > On Wed, Dec 30, 2009 at 7:15 AM, Adam Playford > wrote: >> >> I'm not an expert on this, but a few thoughts. >> >> First, if I'm reading your message right, it sounds like your problem >> probably isn't with the query, but with how many times you're running >> it. > > I'll echo that... the problem is not the database - the queries are as good > as it gets. The problem is running them repeatedly. > > If all else fails, I'd replace those queries that execute 500 times with raw > SQL that uses the IN operator to get the required rows. > > E.g.: SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` FROM > `common_addresstype` WHERE `common_addresstype`.`id` IN (1,6,8,52,173) > > I imagine there's an ORM query that will do the same thing, but I know MySQL > far better than I know Django. > > Nick > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: error in the example
Hi, Python's parser use indentation to indicate logical blocks. Read more here: http://www.secnetix.de/olli/Python/block_indentation.hawk http://diveintopython.org/getting_to_know_python/indenting_code.html http://docs.python.org/reference/lexical_analysis.html#indentation You have 3 spaces before word "class" and 4 is standard which you may have been using (even not being aware of it) - try change that. If not, try to figure out where you have wrong indentation. If you wouldn't be able to fix the code put content of the file at http://pastebin.com/ and write here again with link to it. Hope it helps On Dec 31, 2009, at 12:24 AM, gintare wrote: > IndentationError -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: error in the example
On Wed, Dec 30, 2009 at 6:24 PM, gintare wrote: > Hello, > > In short > OS Debian Gnu Linux Lenny > Python 2.5 > Installed Django-1.1.1.tar.gz, > /usr/lib/python-django/Django-1.1.1/docs/intro/tutorial01.txt > > command python manage.py sql polls > gives error: IndentationError: unexpected indent > in File "/mano/mysite3/../mysite3/polls/models.py", > line 5 > class Poll (models.Model): > > What is wrong with syntax in this line "class Poll (models.Model):" ? > > Looks like you have a space or two in front of the word "class". Spaces are meaningful in Python. -Doug > > --- > trying according example: > /usr/lib/python-django/Django-1.1.1/docs/intro/tutorial01.txt > > the sequence of the commands, which went fluently was: > > `django-admin.py startproject mysite3' > (i have to make adjustments to settings.py choosing Sqlite3 and > creating database) > > python manage.py runserver > python manage.py syncdb > python manage.py startapp polls > > creates folder polls with file models.py into which i have to paste > code from tutorial01.txt > . >class Poll(models.Model): >question = models.CharField(max_length=200) > . > > the next command python manage.py sql polls > gives error: IndentationError: unexpected indent > in File "/mano/mysite3/../mysite3/polls/models.py", > line 5 > class Poll (models.Model): > > > -- > The whole error report: > > working:/mano/mysite3# python manage.py sql polls > Traceback (most recent call last): > File "manage.py", line 11, in >execute_manager(settings) > File "/usr/lib/python2.5/site-packages/django/core/management/ > __init__.py", line 362, in execute_manager >utility.execute() > File "/usr/lib/python2.5/site-packages/django/core/management/ > __init__.py", line 303, in execute >self.fetch_command(subcommand).run_from_argv(self.argv) > File "/usr/lib/python2.5/site-packages/django/core/management/ > base.py", line 195, in run_from_argv >self.execute(*args, **options.__dict__) > File "/usr/lib/python2.5/site-packages/django/core/management/ > base.py", line 221, in execute >self.validate() > File "/usr/lib/python2.5/site-packages/django/core/management/ > base.py", line 249, in validate >num_errors = get_validation_errors(s, app) > File "/usr/lib/python2.5/site-packages/django/core/management/ > validation.py", line 28, in get_validation_errors >for (app_name, error) in get_app_errors().items(): > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", > line 131, in get_app_errors >self._populate() > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", > line 58, in _populate >self.load_app(app_name, True) > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", > line 74, in load_app >models = import_module('.models', app_name) > File "/usr/lib/python2.5/site-packages/django/utils/importlib.py", > line 35, in import_module >__import__(name) > File "/mano/mysite3/../mysite3/polls/models.py", line 5 >class Poll(models.Model): >^ > IndentationError: unexpected indent > > regards, > gintare > g.statk...@gmail.com > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
error in the example
Hello, In short OS Debian Gnu Linux Lenny Python 2.5 Installed Django-1.1.1.tar.gz, /usr/lib/python-django/Django-1.1.1/docs/intro/tutorial01.txt command python manage.py sql polls gives error: IndentationError: unexpected indent in File "/mano/mysite3/../mysite3/polls/models.py", line 5 class Poll (models.Model): What is wrong with syntax in this line "class Poll (models.Model):" ? --- trying according example: /usr/lib/python-django/Django-1.1.1/docs/intro/tutorial01.txt the sequence of the commands, which went fluently was: `django-admin.py startproject mysite3' (i have to make adjustments to settings.py choosing Sqlite3 and creating database) python manage.py runserver python manage.py syncdb python manage.py startapp polls creates folder polls with file models.py into which i have to paste code from tutorial01.txt . class Poll(models.Model): question = models.CharField(max_length=200) . the next command python manage.py sql polls gives error: IndentationError: unexpected indent in File "/mano/mysite3/../mysite3/polls/models.py", line 5 class Poll (models.Model): -- The whole error report: working:/mano/mysite3# python manage.py sql polls Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "/usr/lib/python2.5/site-packages/django/core/management/ __init__.py", line 362, in execute_manager utility.execute() File "/usr/lib/python2.5/site-packages/django/core/management/ __init__.py", line 303, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python2.5/site-packages/django/core/management/ base.py", line 195, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib/python2.5/site-packages/django/core/management/ base.py", line 221, in execute self.validate() File "/usr/lib/python2.5/site-packages/django/core/management/ base.py", line 249, in validate num_errors = get_validation_errors(s, app) File "/usr/lib/python2.5/site-packages/django/core/management/ validation.py", line 28, in get_validation_errors for (app_name, error) in get_app_errors().items(): File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 131, in get_app_errors self._populate() File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 58, in _populate self.load_app(app_name, True) File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 74, in load_app models = import_module('.models', app_name) File "/usr/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/mano/mysite3/../mysite3/polls/models.py", line 5 class Poll(models.Model): ^ IndentationError: unexpected indent regards, gintare g.statk...@gmail.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to check this Ajax function's status
Hello, Just wonder if somebody can tell me how to check this Ajax function's status in template. Here is what I have. In my views.py there is an Ajax function def ajaxTable_traffic(request, pid, ...): return HttpResponse("cacheHashCallback_traffic"..) --- "cacheHashCallback_traffic(...)" is a javaScript function in template. Now there is another function "checkStatus(...)" in javaScript. In order to run some scripts in this function, it needs to know the status of "cacheHashCallback_traffic(...)" . something is like following function checkStatus(...) { check status of cacheHashCallback_traffic(...) if its status == 4 do some stuff else wait until cacheHashCallback_traffic(...) has finished running then do some stuff } Can anybody tell me how to check the running status of "cacheHashCallback_traffic(...)"? 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Is it possible to change order of elements in model?
Hello ev, On Dec 30, 2:19 pm, ev wrote: > Example: I have a playlist and I want to have a possibility to change > songs order (manually, not by name or raiting). > > This task could be done by adding to the model an integer field (to > remember the order): > ordering=models.IntField() An order field seems to be a standard way of doing it. I do it that way for some of my models. > I'd like to know, if there is any feature to realize such a > functionality in Django. Could you be a little more explicit about what you want to do? Are you wondering if Django has a GUI to control the order of items in a list such as a song playlist? I'm pretty sure the answer is no. However, you can use 3rd party utilities and integrate them into your website. Here is one such solution < http://www.djangosnippets.org/snippets/1053/ >. Toodle-lo... creecode -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django Admin Template Directory
I have exactly the same problem.. On Nov 3, 1:13 pm, Ludwik Trammer wrote: > > I didn't specify a path. I did an apt-get install on Ubuntu 9.04 > > Than it should be under "/var/lib/python-support/python2.6/django/" > > Ludwik > > PS: "whereis" locates only binary and man files. You may want to use > "locate" or "find" instead. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: JavaScript function call
Great. Thanks Kevin! On Dec 29, 1:28 am, Kevin Renskers wrote: > First of all, in your template include jQuery: > http://ajax.googleapis.com/ajax/ > libs/jquery/1.3/jquery.min.js"> > > Create a new javascript file, and put the following code in it: > > // This is automatically run when the document has been completely > loaded > $(function() { > // Find all tr's in your table (give your table an id) > $('#your_table_id tr').each(function() { > // Give your tr's an id like {{v.publisher_id}}_ > {{v.country_id}} > // We now split that id on the underscore and get the parts we > need. > temp = this.id.split('_'); > publisher_id = temp[0]; > country_id = temp[1]; > > // Call your function however you like > showDomainTable(publisher_id, country_id); > }); > > }); > > Include this new javascript in your template too, and give your table > an id. > This code is just from the top of my head, but it should work alright. > > On Dec 28, 11:24 pm, "gilbert F." wrote: > > > Hi Kevin, > > > Sorry I could not make progress therefore I am considering to use > > jQuery. As I never used it, can I have your jQuery code for reference? > > You may send to my e-mail gilber...@gamil.com > > > Thanks so much. > > > On Dec 28, 9:19 am, "gilbert F." wrote: > > > > Hi Kevin, > > > > Thanks so much for your replies. Following your suggestions I have > > > moved tag out of. > > > > > > >