django

Django model refactoring and migration.

I'd like to refactor a number of django apps in a way which involves moving Models from one app into another where they can be more readily reused. A number of these models have either ForeignKey relationships or M2M relationships to other models (such as User). For example: class Department(models.Model): name = models.CharField...

Retrieving tags for a specific queryset with django-tagging

I'm using django-tagging, and am trying to retrieve a list of tags for a specific queryset. Here's what I've got: tag = Tag.objects.get(name='tag_name') queryset = TaggedItem.objects.get_by_model(Article, tag) tags = Tag.objects.usage_for_queryset(queryset, counts=True) "queryset" appropriately returns a number of articles th...

Can Django/Javascript handle conditional "Ajax" responses to HTTP POST requests?

How do I design a Django/Javascript application to provide for conditional Ajax responses to conventional HTTP requests? On the server, I have a custom-built Form object. When the browser POSTS the form's data, the server checks the submitted data against existing data and rules (eg, if the form adds some entity to a database, does tha...

Django: How to access originating instance from a RelatedManager?

I would like to access the Foo instance foo within my manager method baz: foo.bar_set.baz() baz would normally take an argument of Foo type: BarManager(models.Manager): def baz(self, foo=None): if foo is None: # assume this call originates from # a RelatedManager and set `foo`. # Otherw...

How can I tell whether I'm on an add or edit page in Django's Admin?

For the following code: class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): author = models.ForeignKey(Author) title = models.CharField(max_length=100) class BookInline(admin.TabularInline): model = Book extra = 1 class AuthorAdmin(admin.ModelAdmin): inlines = [ ...

django query db on every request

i have a navigation element that is determined by values in a database. no matter what view it is, i need to get these navigation objects out of the database. where in the code can i tell it to set a template variable containing all the navigation objeccts without setting it in every view? ...

model/view relationships

i have a model ready with the various form fields. how do i make those form fields get saved into the database? i tried reading the form documentation but it is so confusing. i know if i get it working, i will understand. can anyone help define a views.py function? ...

Django: Get an object form the DB, or 'None' if nothing matches

Is there any Django function which will let me get an object form the database, or None if nothing matches? Right now I'm using something like: foo = Foo.objects.filter(bar=baz) foo = len(foo) > 0 and foo.get() or None But that's not very clear, and it's messy to have everywhere. ...

Generic Foreign Keys and get_or_create in django 1.0: Broken?

As you can see, create() works, but get_or_create() doesn't. Am I missing something obvious here? In [7]: f = FeedItem.objects.create(source=u, dest=q, type="greata") In [8]: f, created = FeedItem.objects.get_or_create(source=u, dest=q, type="greata") --------------------------------------------------------------------------- FieldErro...

How to access YQL in Python (Django)?

Hey, I need a simple example for the following task: Send a query to YQL and receive a response I am accessing public data from python backend of my Django app. If I just copy/paste an example from YQL, it says "Please provide valid credentials". I guess, I need OAuth authorization to do it. So I got an API key and a shared secret. N...

text diff on django/google appengine

I am developing a wiki using django which i plan to deploy later in google appengine. Is it possible to deploy textdiff like system in appengine? ...

AppEngine/Django: editing db.Key in the Admin app

Or, to be precise, how do I properly present a form to edit a db.ListProperty of db.Keys on a model admin page, with app-engine-patch for Django? I have a Category like this: class Category(db.Model): title = db.CategoryProperty(required=True) and a Post with this: categories = db.ListProperty(db.Key) Currently in the Django a...

Django: How to format a DateField's date representation?

Hello, I have a Form with a DateField. The formatted date look like this: 2009-10-03 How can i Format that? I want it look like this: 03.10.2009 I found a widget which renders it like this, but validation doesnt allow the values i enter then... Bye falstaff ...

App Engine GQL: querying a date range

What would be the App Engine equivalent of this Django statement? return Post.objects.get(created_at__year=bits[0], created_at__month=bits[1], created_at__day=bits[2], slug__iexact=bits[3]) I've ended up writing this: Post.gql('WHERE created_at > DATE(:1, :2, :3) AND created_at < DATE(:1, :2, :4) and slug = :5'...

Following a foreign-key of a commented item in a Django Queryset

Dear all, I'm working on a Django application allowing one to comment either a Text, its Paragraphs or the comments themselves. I'm using the Comment app bundled with Django, and A Text class instance is made up of Inline Paragraph class instances. I'm desperately looking for a way get back a QuerySet/List of all the Comments related d...

Learning the Django framework

Django is a great framework, but after seeing a couple of learning videos I realized those people have great knowledge of the Django framework and libraries, which enable them to use any class very easily. I just wonder how can one remember all those classes and function in an environment where IDEs are not powerful enough. What shou...

Request data from database using Django

I have somehow two variables for example x and y. I have also made a model with 3 fields (longitude,latitude,name) and have it activated in mysql database. I need to send these two variables(x,y) to the django server so as to search if there is an object with longitude=x and latitude=y.If there is one i want to get back it's name. How c...

GqlQuery OrderBy a property in a ReferenceProperty

Hi all, I don't know how to make a GqlQuery that order by a property of the ReferenceProperty. In this case, I want to get all the Seat but order by the id of the Room The GqlQuery reference does not allow a join, so how do you approach in this case? class Room(db.Model): id = db.IntegerProperty() dimension = db.StringPropert...

cherrypy vs django

cherrypy vs django, which would you use and why ...

Display Pretty Code in Django

I'm looking for something I can use within django to display preformatted code. Ideally this would include out-of-the-box syntax highlighting for various programming languages, although just starting with something that displayed html and xml well would be a good starting point. Does something like this exist? Basically I am looking...