django

django python - generic views and cookies

Hi, I made in my web a menu using generic_view - simple 'django.views.generic.list_detail.object_list' in urls.py file. I would like to set a cookies each time when user chooses one of element of this list [HttpResponse.set_cookie(...)]. What is the best solution? Should I write function in views.py or have you got more simple solution? ...

Suggestions required for generating this logging file structure in django project

Hi Can anyone please suggest how to generate log files having following directory-file structure using python logging in django project. logs/2009-03-09 /errors.log /warnings.log /info.log /emails.log /messages.log logs/2009-03-08 /errors.log /warnings.log ...

Django while loop

Hi, I wonder if there's any way to do a while loop in django (I think that's what I'm after)? What I'm trying to do is a nestled ul/li list. The list is generated by a for loop in a for loop. But since some elements in the second for loop has more child's I want to iterate or them to and so on until all child nodes are iterated out. O...

more than 1 foreign key

I have the following models: http://slexy.org/view/s20T8yOiKZ from mxutils.cms_services import generate_secid from django.db import models from django.contrib import admin from django import forms class World(models.Model): title = models.CharField(max_length=150) secid = models.SlugField(max_length=1000, editable=False) el...

Django: How can I implement a low level login using a md5 password column since I'm porting over my users table from an old site?

Basically, I currently have login/ in urls.py redirect to the django.contrib.auth.views.login and that seems to work out fine. However I'm porting over passwords from a legacy mysql/php site and I believe I should just create a new model profile per http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-u...

Django: Setting up a user profile page?

I'm still a novice and I'm not sure how I should setup the profile page for users. The django.contrib.auth.views.login will redirect to a accounts/profile page, but how should I actually set this up? Is it common to just define accounts/profile in urls.py and have it redirect to a template or is it a more complex pattern? django.views....

django annotate queryset based on attribute

Hi, is there a way to do the following in one Django query? MyModel.filter(attr=a).values('attr','fields','of','interest').annotate(count=Count('id')) MyModel.filter(attr=b).values('attr','fields','of','interest').annotate(count=Count('id')) edit: I need separate counts for a and b. MyModel.filter(attr__in=(a,b))... or MyModel.filter...

How do I get the values of the lastest entries grouped by an attributes using Django ORM?

I have a report model looking a bit like this: class Report(models.Model): date = models.DateField() quantity = models.IntegerField() product_name = models.TextField() I know I can get the last entry for the last year for one product this way: Report.objects.filter(date__year=2009, product_name="corn").order_by("-date")[0...

Using Vaadin (Java) UI Framework inside Python

What would be the best way to use Vaadin within Python/Django applications? I will be more than satisfied with having access to components/widgets, if the whole UI framework cannot be exposed to me directly. I am aware of Jython, but I am still not sure if it's the way to go about Vaadin in a Python web application. Any positive input/s...

jqgrid with JSON input rendering empty

I'm trying to generate a jqgrid which populates from a JSON feed, being output from a django backend. The python handling the request is as follows: from django.http import HttpResponse from django.utils import simplejson def json_test(request): results = {'total':'1', 'page':'1', 'records':'2', ...

GAE Django Table Records Pagination?

Anyone have sugestion or example on how displaying Google Datastore records table with pagination on Google App Engine django template? Something like Gmail pagination. ...

Django: What's wrong with my simple ajax experiment?

I am trying to understand how Django + Jquery and Ajax calls work together. It is just a simple /test/ url that shows a single input form, once submitted retrieves the answer from the server via ajax. For that I have written a very small view: def test(request): if request.is_ajax(): from django.http import HttpResponse ...

How to load sql fixture in Django for User model?

Hi folks, Does anyone knows how to load initial data for auth.User using sql fixtures? For my models, I just got have a < modelname >.sql file in a folder named sql that syncdb does it's job beautifully. But I have no clue how to do it for the auth.User model. I've googled it, but with no success. Thanks in advance, Aldo ...

Good ways to sort a queryset? - Django

Hi folks, what I'm trying to do is this: get the 30 Authors with highest score ( Author.objects.order_by('-score')[:30] ) order the authors by last_name Any suggestions? ...

Wrapping a non-generic Django view

I want to inject one additional variable into the context of a view that belongs to a 3rd-party application without editing the code of that application. Is there a way to do this by wrapping the (non-generic) view? It doesn't accept an extra_context parameter, so the approach described in this SO thread won't work. I know I could create...

Django: problem with merging querysets after annotation

Hi I have a manager for "Dialog" looking like this: class AnnotationManager(models.Manager): def get_query_set(self): return super(AnnotationManager, self).get_query_set().annotate( num_votes=Count('vote', distinct=True), num_comments=Count('comment', distinct=True), num_commentators = Count('comment__user',...

Circular import issues with Django apps that have dependencies on each other

Hi, I am writing a couple of django apps wich by design is coupled together. But i get sircular import problems. I know it might be bad design, so please give examples of better solutions, but i cant seem to find a better suited design. So if there isnt a better design, how to solve this one? It is basically two django apps, with some ...

What is the user's username?

In one of my Django models, I override the save function. I do this to get the user's username. But that keeps failing. this is what i did: def save(self, *args, **kwargs): self.slug = slugify('%s' % (self.question)) if not self.id: self.publish_date = datetime.datetime.now() self.publisher = self.request.us...

How could I rewrite this loop of Django queries as a more efficient SQL query?

This is an inefficient way to update a denormalized field on an Player Django model. The field essentially stores the position of the player on the leaderboard, which is a requirement for a system we have for displaying "nearby" players to a given player. for position, player in enumerate(Player.objects.order_by('-score')): player.p...

Simulating Google Appengine's Task Queue with Gearman

One of the characteristics I love most about Google's Task Queue is its simplicity. More specifically, I love that it takes a URL and some parameters and then posts to that URL when the task queue is ready to execute the task. This structure means that the tasks are always executing the most current version of the code. Conversely, my ...