django

Django __in lowercase

Hi there, I'm using django-taggit, which handles the attachment of tags to arbitrary content types. I imported a large tag list, which contains many uppercase words, as well as lowercase words. Now, I' trying to get objects of another class containing a set of tags, but I want to compare case insensitively. When I do this: Media.objec...

Python solution to allow photo uploading via email to my Django website

I am learning Python/Django and my pet project is a photo sharing website. I would like to give users the ability to upload their photos using an email address like Posterous, Tumblr. Research has led me to believe I need to use the following: -- cron job -- python mail parser -- cURL or libcurl -- something that updates my database ...

Django + ThumbnailerImageField: null value in column "storage_id"

from easy_thumbnails.fields import ThumbnailerImageField class Test(models.Model): image = models.ImageField(null=True, blank=True, upload_to="test") easy_thumbnail = ThumbnailerImageField( null=True, blank=True, upload_to="test/easy_thumbnails", resize_source=dict(size=(100, 100), crop="smart"), ) ...

Checking another field at the same time as checking a many-to-many relationship.

I have a simple-ish ownership design on one of my models. It can be owned by multiple people and current owners can add other people but they have to confirm the invite before they are treated as a real owner. class MyOwnedThing(models.Model): owners = models.ManyToManyField(User, through='Ownership', related_name='othings') de...

How can I automatically let syncdb add a column (no full migration needed)

When I make a change to my models (only to add a column during development!), Django won't issue any ALTER TABLE statements to update the database. Is there a way to get this implemented or worked around? - other then adding the columns manually? Note I'm not really looking for a full-migration solution, just something that lets me ke...

Anyone with experience on django-preferences app or similar?

Hello, Im still trying to embed a page in my admin site where I can let the user to change some global variables (like in wordpress) such as the site name, meta keywords, etc. Apparently there is an app that does this but I cannot get it to work (Im using Django 1.3): http://github.com/praekelt/django-preferences NOTE: I tried both fro...

Django: Calling ModelForm via instance method - seperate fields

Is it possible to output a ModelForm using a class method; for example: def edit_form(self, *args, **kwargs): from smf.node.forms import MediaBaseForm return MediaBaseForm(instance=self) (MediaBaseForm is a ModelForm subclass for model Media), and then in the view: form = node.edit_form() (node contains the instance) This c...

Django admin site: implement a singleton for global variables?

Does anyone have experience (Django 1.x pref 1.3) with implementing a sort of singleton accessible from the admin page to expose some global variables for editing (site name, keywords, ...). I cant find anything like this and it sounds quite unbelievable! thanks (django-preferences is broken with 1.x) ...

Django: How to check if field widget is checkbox in the template?

I've created a custom template for rendering form fields: <tr class="{{field.field.widget.attrs.class}}"> <th class="label"> <label for="{{field.auto_id}}"> {{field.label}} {% if not field.field.required %}<span class="optional">(optional)</span>{% endif %} </label> </th> <td class="fi...

Django: How to override form.save()?

My model has quite a few boolean fields. I've broken these up into 3 sets which I'm rendering as a MultipleChoiceField w/ a modified CheckboxSelectMultiple. Now I need to save this data back to the DB. i.e., I need to split the data returned by a single widget into multiple boolean columns. I think this is appropriate for the save() met...

Add unit to yaxis labels in MatPlotLib

I am trying to add mi or km (miles, kilometers) after the value on the yaxis of a matplotlib bar chart. Right now I am just supplying matplotlib the values and it is making the yaxis labels automatically. I can't figure out how to append mi to the end of a value. 24 > 24 mi There is an option for ax.set_7ticklabels(), but then I ...

Django, auto generating unique model fields and recursively calling auto generator if not unique

I am working on a Django project where a Thing would have a unique 10 digit Key, in addition to the standard auto incrementing ID integerfield. I use a simple random number function to create it. [I'm sure there's a better way to do this too] When a Thing is created, a 10 digit Key is created. I use the .validate_unique() to check th...

How to override a field value before validation?

I've got a form for which I need to set a few values before validation. I'm trying: if request.method == 'POST': reservation_form = ReservationForm(request.POST, initial={'is_reservation':True, 'user':request.user}) But it doesn't work. If I exclude the 'user' field from the (model)form, I get a null-constraint error, if I do incl...

Send files from form directly to remote server

In my application I'm dealing with upload of really big image files. They will be stored on a remote server, so from what I was able to learn I need to write some custom Storage system (probably with the use of python's poster module). Because of the size I would like to send the files directly to media server without storing them in mem...

500 Error when sending file from python to django

I've found a nice python module for sending data to remote servers via HTTP POST called poster. So I've wrote a simple view on my django app to receive and store data and then tried to send some file. Unfortunatelly even though I've set everything as it was shown in the instruction I'm getting Internal Server Error. Can anyone maybe see ...

Django admin site: How does the Add User page works (more fields on edit) ?

I was wondering how they made it possible to display more fields in the User page of the djagno admin site. If you create a new User you only have some basic fields to fill in but if you reopen that user (edit mode) then you see a lot more fields to fill in. Im trying to achieve the same, I had a look at the add_form.html template but I...

Can we create interactive PDF forms using reportlab?

Can we create interactive PDF forms using reportlab? That is, a form that takes in data from readers and save them into the database. ...

How can you manually render a form field with its initial value set?

I'm trying to render a form's fields manually so that my designer colleagues could manipulate the input elements within the HTML instead of struggling in Python source. ie. Instead of declaring form fields like this... {{ form.first_name }} .. I actually do ... <label for="id_first_name">Your name:</label>...

Monkey patching a Django form class?

Given a form class (somewhere deep in your giant Django app).. class ContactForm(forms.Form): name = ... surname = ... And considering you want to add another field to this form without extending or modifying the form class itself, why does not the following approach work? ContactForm.another_field = forms.CharField(...) (...

Need Formset for relationship model with forms for all instances of one ForeignKey

I have a ManyToMany field with a relationship model. I want a formset, filtered on one of the keys, which shows a form for each of the other keys. My guess is that a custom manager on the relationship model is the key to solving this problem. The manager would return "phantom" instances initialized with the appropriate ForeignKey when n...