django

Django - Add online columns in "select"

I dont know if this is the best way to resolve my problem, if isn't , tell me plz :) I have this model : class userTrophy(models.Model): user = models.ForeignKey(userInfo) platinum = models.IntegerField() gold = models.IntegerField() silver = models.IntegerField() bronze = models.IntegerField() level = models.IntegerF...

Truncating unicode so it fits a maximum size when encoded for wire transfer

Given a Unicode string and these requirements: The string be encoded into some byte-sequence format (e.g. UTF-8 or JSON unicode escape) The encoded string has a maximum length For example, the iPhone push service requires JSON encoding with a maximum total packet size of 256 bytes. What is the best way to truncate the string so that...

Django Dynamic Forms Save

I am using James Bennetts code (link text) to create a dynamic form. Everything is working ok but I have now come to the point where I need to save the data and have become a bit stuck. I know I can assess the data returned by the form and simply save this to the database as a string but what I'd really like to do is save what type of ...

Get type of Django form widget from within template

I'm iterating through the fields of a form and for certain fields I want a slightly different layout, requiring altered HTML. To do this accurately, I just need to know the widget type. It's class name or something similar. In standard python, this is easy! field.field.widget.__class__.__name__ Unfortunately, you're not allowed access ...

Django, Cannot assign None, does not allow null values

i have this models.py import datetime from django.db import models from tinymce import models as tinymce_models from filebrowser.fields import FileBrowseField class ItemWithMedia(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) class Actual(ItemWithMedia): publ...

Only validate certain fields if a BooleanField is set

Scenario: I'm building an order-form. Like every other order-form on the planet, it has separate invoicing shipping addresses. I've just added a "Use billing address" checkbox to let the user save time. The problem is, the shipping fields are still there. They will fail validation if the user don't enter any shipping address data (like ...

Django: How to filter User's that belong to a specific group

I'm looking to narrow a query set for a form field that has a foreignkey to the User's table down to the group that a user belongs to. The groups have been previously associated by me. The model might have something like the following: myuser = models.ForeignKey(User) And my ModelForm is very bare bones: class MyForm(ModelForm):...

Monitor database requests in Django, tied to line number

We've got some really strange extraneous DB hits happening in our project. Is there any way to monitor where the requests are coming from, possibly by line number? The SQL printing middleware helps, but we've looked everywhere those kinds of requests might be generated and can't find the source. If the above isn't possible, any pointers...

Display thumbnails in an object list using Django and django-imagekit

How do I display thumbnails for my item list....also is it possible to display just a specific thumbnail or a random thumbnail? So far I have this in my template: {% for p in item.images.all %} {{ p.get_thumbnail.url }} {% endfor %} ...

New Satchmo page is missing some store settings

If I add a new template and view to a satchmo install within my project it renders just fine, but it seems to be missing some values like the name of the store and it does not register that I am logged into the site when I am on the new pages. If I check the request.user it appears to be authenticated, but base.html does not render the ...

manage.py syncdb on windows for Google App Engine Patch does not work

I have installed Google App Engine patch and I get the following error when I want to sync the DB Command on command prompt on windows manage.py syncdb The Google App Engine SDK could not be found!Visit http://code.google.com/p/app-engine- patch/ for installation instructions. I have installed win32api too and it still recurs. a...

Django custom handler404 shows 404 but gives header 200

Hi all, I made a custom handler404 for a authenticated Django website to avoid information leakage. def check_logged_in_404(request): """ Custom 404. Show friendly 404 when logged in and redirect to /login when not logged in. """ if request.user.is_authenticated(): return render_to_response('404.html') else...

Allow null in foreign key to user. Django

I have this model class Vacancy(models.Model): user = models.ForeignKey(User, null=True, blank=True, default = None) name = models.CharField(max_length=64) When in admin i try to creat a vacancy without a user. And it throws an error " club_vacancy.user_id may not be NULL". Am i doing something wrong? ...

How do I delete an instance of an intermediate model in a Django Many-to-many relationship?

According to an example at http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships I have three models: class User(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(User, through...

Django CSRF problems with cookies disabled

Hi there, While testing an application I've written in Django, I've found that I'm be thrown a HTTP 403 Forbidden error every time I submit a form. I am aware that the CSRF middleware checks for a cookie with the CSRF token - but what should my approach be given a user that has cookies disabled? Do I need to be checking whether the use...

django blocktrans and i18n in templates

Hi, looking for a while with i18n problem in django: this work fine : {% trans cat.name %} cat.name will be translated but this doesn't work: {% blocktrans with cat.name|slugify as cat_slug %}{{ cat_slug }}{% endblocktrans %} cat.name is not translated if I change the filter : {% blocktrans with cat.name|capfirst as cat_slug %}{{ cat_...

Any good tutorials on using OAuth with Piston?

I've looked at the relevant section of the Piston documentation, but it only seems to focus on how to turn it on, not what it would look like for clients or how to test it to verify it's working. The example only seems to use HTTP Basic and curl. Finally, Ned Batchelder's question makes it look like a tutorial is in order. Thanks. ...

Django, how to generate an admin panel without models?

Hi, I'm building a rather large project, that basically consists of this: Server 1: Ice based services. Glacier2 for session handling. Firewall allowing access to Glacier2. Server 2: Web interface (read, public) for Ice services via Glacier2. Admin interface for Ice services via Glacier 2. The point I'm concerned with is the...

How to deal with "None" DB values in Django queries

Hello, I have the following filter query which is doing an SQL OR statement: results = Stores.objects.filter(Q(title__icontains=prefs.address1) | Q(title__icontains=prefs.address2)) This works fine but if the prefs.address1 and prefs.address2 values (which come from another model) are blank in mySQL, Django complains with the followi...

A puzzle concerning Q objects and Foreign Keys

I've got a model like this: class Thing(models.Model): property1 = models.IntegerField() property2 = models.IntegerField() property3 = models.IntegerField() class Subthing(models.Model): subproperty = models.IntegerField() thing = modelsForeignkey(Thing) main = models.BooleanField() I've got a function that is...