django

AttributeError - Django, GAE

This is my code for views.py def addCategory(request): user = users.get_current_user() if users.is_current_user_admin(): if request.method == 'POST': form = CategoryForm(request.POST) if form.is_valid(): cd = form.cleaned_data Category.objects.create_category(cd['na...

Django: request.GET and KeyError

Code: # it's an ajax request, so parameters are passed via GET method def my_view(request): my_param = request.GET['param'] // should I check for KeyError exception? In PHP Frameworks I typically have to check for parameter to exists and redirect user somewhere if it does not. But in Django unexisted parameter results in 500 error...

Can I add a manager to a manytomany relationship?

I have two models that has a manytomany relationship with a 'through' table in some way? class Bike(models.Model): nickname = models.CharField(max_length=40) users = models.ManyToManyField(User, through='bike.BikeUser') The BikeUser class class BikeUser(models.Model): bike = models.ForeignKey(Bike) user = model...

Django: TEMPLATE_DIRS vs INSTALLED_APPS

I am currently just add app to INSTALLED_APPS to be able to use templates from that app, but there is also TEMPLATE_DIRS setting. When have I to prefer TEMPLATE_DIRS over INSTALLED_APPS? ...

django forms error not shown

Hello, I'm trying to create a form. Here is my form class: class RegisterForm(forms.Form): login=forms.CharField(min_length=5,max_length=15) password=forms.CharField(min_length=5,max_length=15,widget=forms.PasswordInput) passwordConfirmation=forms.CharField(min_length=5,max_length=15,label="Re enter password",widget=forms.PasswordInput)...

Google App Engine or Django?

I've been learning Python and now I'd like to learn a Python-based web framework. I'm considering Google App Engine and Django. Which one should I choose? What are their unique features and learning curves? ...

Django: Custom model manager problem

I am trying a simple custom manager, but I can't concatenate custom queries: class MyManager(models.Manager): def some_filter(self): qs = self.get_query_set() return qs.filter(score__gt = 10).order_by("-score") class Game(models.Model): score = models.IntegerField(blank=True, default=0) objects = MyMana...

Django not cascading on delete.

I'm realizing more and more that I'm still a Django noob, I can't seem to figure out what's happening with my data model and why it's not cascading deletes. Here is my model. class message(models.Model): msg_text = models.CharField(max_length = 9900) date_time = models.DateTimeField() is_read = models.BooleanField(defaul...

How can I use django's built-in server behind nginx?

I'm developing with apache2 ( mpm-worker ) + mod_wsgi behind nginx which is silly since I have to sudo apache2ctl graceful for every update I make in anything but the template files. My nginx conf is: server { listen 80; server_name site.org; access_log /www/site.org/log/access.log; error_log /www/site...

Help with Django Query

Hi Guys: I need to make this Query using Django QuerySystem. SELECT DATE(`date`), count(*) FROM `maggie_item` GROUP BY DATE(`date`) DESC My model: Item date = DateTime title = textfield I would appreciate your help ...

django template does not render complete context

Hello, I am using templates with django. I am having a problem where the Context is not being rendered. The meta_k is null. The meta_description is not. t = get_template('projects.html') html = t.render(Context({ 'completed': completed, 'current':current, 'description': sp.description, 'project_tit...

Confusion about django app's name

I learned Django following django book and the document. In the django book exmaple, the project is called mysite and there's an app called book inside this project. So in this case, the app is called "book". I've no problem with it. My confusion arises in front of reusable apps. Reusable apps usually reside outside the project. For exa...

Python: how to use value stored in a variable to decide which class instance to initiate?

I'm building a Django site. I need to model many different product categories such as TV, laptops, women's apparel, men's shoes, etc. Since different product categories have different product attributes, each category has its own separate Model: TV, Laptop, WomensApparel, MensShoes, etc. And for each Model I created a ModelForm. Hence ...

Creating an inline admin which displays the final model instead of the GenericForeignKey link table.

The models below show a simple GenericForeignKey relationship. It has been set up in this way to allow an Image to be reused by any other model. class Image(models.Model): name = models.CharField(max_length=150) desc = models.TextField(max_length=400) resource = models.ImageField(upload_to='imgs/generic/%Y/%m/%d') def _...

django compressor and clevercss with absolute url paths

when using django, compressor, and clevercss, i set my css url to an absolute path. clevercss is then passed the path of the .ccss file without the COMPRESS_ROOT prefixed (the absolute path). when i set my css url to a relative path, clevercss processes the ccss files, but the browser then correctly looks for relatively placed css files ...

Django and Buildout Deployment Problem

I am trying to deploy my existing django project via buildout, following loosely the instructions here. my buildout.cfg file is: [buildout] parts = django python develop = . eggs = myproject [django] recipe = djangorecipe version = 1.2.3 project = myproject projectegg = mypr...

Use jQuery to loop through a Django object via. AJAX

Hey, i think this is simple, but I can't get it to work! :( def ajax_filter(request): area_id = request.REQUEST.get('area_id') outlets = Outlet.objects.filter(zipcode__area=area_id) json_serializer = serializers.get_serializer("json")() data = json_serializer.serialize(list(outlets), ensure_ascii=False) return Htt...

Django Context Processors: Is it possible to access current context in ContextProcessor ?

Is there a way I can access current context passed by view in custom context processor so I can add missing variable if I want rather than overriding existing variable ? What I'm trying to Achieve: I construct my URL's like this /city_slug/ and I want to check if city variable already exist in context, otherwise I want to add city to...

gae-sessions and django variable passing.

I am using gae-sessions for the back end session management, the problem that occurs is although I am able to get the data of the session in a self.response.out.write() command when I am trying something simple like session = get_current_session() profile = session['me'] templates.render(self, 'tmp.html', profile=profile) {{profile}...

Django 1.2: Custom form field?

Hi, I've got a dynamic form that contains either one or several MultipleChoiceFields or ChoiceFields. I want to display an instruction to the user, e.g. for ChoiceField: "Select one of the following", and for MultipleChoiceField: "Select any of the following" How can I do this? I tried subclassing each of these fields, but I couldn't ...