django

Django: InlineModelAdmin to reference its own Model

So I am trying to setup an entry posting system, where the user can select a bunch of related entries when creating an entry. And it would be wonderful if I could use the InlineModelAdmin for it. But it keeps wanting a foreignkey, which for some reason I'm unable to set up properly. Here's a simplified setup of my situation: models.py ...

Django : load a restricted set of fields of objects loaded using a foreign key

I have the following code, using Django ORM routes =Routes.objects.filter(scheduleid=schedule.id).only('externalid') t_list = [(route.externalid, route.vehicle.name) for route in routes]) and it is very slow, because the vehicle objects are huge (dozens of fields, and I cannot change that, it is coming from a legacy database)....

Django getting field names from different models

Guys, Is there an easy way to return different fields names from different models by chaining joins? My model: Class Item(models.Model): item_code = models.CharField(max_length=10) name = models.CharField(max_length=255) ... Class Stock(models.Model): item_code = models.ForeignKey( Item ) userid = models.ForeignKey(...

Passing variables beween views

I have two views: def importContent(request): d = get_some_data() t = get_template('import.html') c = Context({'entries' : d.entries }) return HttpResponse(t.render(c)) def doImport(request): return HttpResponse("hey") Here is import.html: {% for entry in entries %} {{ entry.title}} <br> {% endfor %} ...

Django databrowse with custom queryset?

Django's databrowse is very different from the rest of django in that the docs literally don't exist. Has anyone tried to do more that databrowse.site.register on a model? Any code examples? In particular, I've got a model that has a ForeignKey to an auth.Group and I want databrowse to use this queryset instead of .all(): qs = Model.ob...

No results in Django Haystack search

I've read the getting started documentation and several other examples on the web. And this is what my search_indexes.py looks like: from haystack.indexes import * from haystack import site from models import Entry class EntryIndex(SearchIndex): text = CharField(document=True) headline = CharField(model_attr='headline') sub...

How to SelectMany using a Django QuerySet?

Suppose I have two models, A and B, where an A can have multiple Bs related to it. Given a QuerySet of A objects, how can I create a QuerySet containing all the B objects related to all these A objects? For those who also happen to speak LINQ, I want something like this: queryableOfA.SelectMany(a => a.Bs) Even better would be an exam...

How to launch tests for django reusable app?

Can I launch tests for my Django reusable app without incorporating this app to some project? My app uses some models, so it is necessary to provide (TEST_)DATABASE_* settings. Where to store them and how to launch tests? For django project I run tests by: manage.py test, when I use django-admin.py I get: Error: Settings cannot be...

Compare Python Web Frameworks and their respective HTML5 APIs Implementations

If you are familiar with a specific python web framework that has implementations for HTML5 API(s) ie.WebSockets, Forms, WebWorkers, WebStorage, Communication, Geolocation, Canvas, etc. Then please list the name of the framework and its HTML5 capabilities. ...

Conditional login redirect in Django

I know about LOGIN_REDIRECT_URL and I know about <form action="?next={{ next|default:"/foo" }}" method="post"> in django-registration's login.html template. Here's what I want to happen: If a user logs in from the homepage, redirect them to a URL that contains their username (/lists/[username]). If a user logs in from any other pag...

Django Deployment Advice

I have a multi-step deployment system setup, where I develop locally, have a staging app with a copy of the production db, and then the production app. I use SVN for version control. When deploying my production app I have been just moving the urls.py and settings.py files up a directory, deleting my django app directory with rm -rf com...

Do Django ManyToManyManagers cache their data?

Basic model breakdown: Movie and MovieGenre models. The Movie model has a field called genres, which is declared as: genres = models.ManyToManyField(MovieGenre, blank=True) Here is the issue: In [42]: frank = Movie.objects.get(id=122) In [43]: frank.genres.count() Out[43]: 2 In [44]: frank.genres.all() Out[44]: [<MovieGenre: Conc...

In Jinja2, how do you test if a variable is undefined?

Converting from Django, I'm used to doing something like this: {% if not var1 %} {% endif %} and having it work if I didn't put var1 into the context. Jinja2 gives me an undefined error. Is there an easy way to say {% if var1 == None %} or similar? ...

Where is the source code for a Python egg?

I'm attempting to add a video extension to the Python Markdown-2.0.3-py2.7.egg Things aren't working, so I want to use pdb debugger to see what's going on. I can't seem to find the source code to insert pdb. The egg is located here: /usr/local/lib/python2.7/site-packages/Markdown-2.0.3-py2.7.egg Using iPython, I can view the Pyth...

Increating a datime field with queryset.update

My model looks like this class MyModel(models.Model): end_time = DateTimeField() and this is what I'm trying to achieve: m=MyModel.objects.get(pk=1) m.end_time += timedelta(seconds=34) m.save() but I want to do it with update() to avoid race conditions: MyModel.objects.filter(pk=1).update(end_time=F('end_time')+timedelta(secon...

Import statement with Django

I'm having an issue with a failing import statement, it is called by a manage.py command. It works in the manage.py shell. It also recently worked, i've tried to retrace my steps to no avail. Any advice? ...

Django Group By

Hello. I'm writing a simple private messenger using Django and am implementing message threading. Each series of messages and replies will have a unique thread_id that will allow me to string sets of messages together. However, in the inbox view ALL of the messages are showing up, I'd just like to group by the thread_id so that althoug...

how to get video duration in python or django?

hi folks, i need to get the video duration in python (django), the video formats that i need to get are mp4, flv, avi, mov... I have a shared hosting so i have no ffmpeg support. Thanks! sorry for my english. ...

How to work with a JSON string returned by a remote URL (with Django)?

Hi, i have to build an small app in order to show some data from the Google Financial API. I know that i could study it inside out, but I don't have much time. The url http://www.google.com/finance/info?q=MSFT returns this JSON string: // [ { "id": "358464" ,"t" : "MSFT" ,"e" : "NASDAQ" ,"l" : "24.38" ,"l_cur" : "24.38" ,"ltt":"4:00PM E...

How increase KML output performance?

Hi How can I improve this KML generator? We discussed pre-generating the output like a cron job perhaps saving a blob to blobstore since it can't serve many markers like this. Can you recommend me how to proceed? Is the bottleneck where using images? class KML(webapp.RequestHandler):#get max, make static or cron job save file like blob ...