django

Easiest way to write a Python program with access to Django database functionality

Hi I have a website which fetches information from RSS feeds periodically (well, currently manually, and this is my problem). This is currently implemented as a normal Django view, which isn't very nice in my opinion. I'd like to have a Python program which is run using a cronjob instead of manually visiting the correct URL to update ...

Model inheritance approach with Django's ORM

Hello, I want to store events in a web application I am fooling around with and I feel quite unsure about the pros and cons of each respective approach - using inheritance extensively or in a more modest manner. Example: class Event(models.Model): moment = models.DateTimeField() class UserEvent(Event): user = models.ForeignKe...

Django admin, custom view error : invalid literal for int() with base 10

I'm trying to make a custom view in Django admin. I'm reading from this site, Simple Django Admin Preview, but I have a problem: ValueError: invalid literal for int() with base 10: '13/preview' Here is my url.py: url(r'^admin/diligencias/diligencia/(?P<object_id>\d+)/preview/$','preview'), Here is my view.py: @staff_member_require...

what may cause a Page Not Found error in flatpages?

Hello all, I just setup django's flatpages app following http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/ Everything is fine, but when i link to a flatpage, i always get: Page not found (404) Request Method: GET Request URL: http://example.com/about/ [..] The current URL, about/, didn't match any of these. what ...

Django, register user with first name and last name?

I'm using Django-Registration and the form just has 3 fields (Username, Email, Password, and Re-password), but why I can't add last name and first name?? In the Form all is fine but the User Model just accepts 3 arguments: new_user = User.objects.create_user(username, email, password) but why I can't do that: new_user = User.objects...

Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found

Hello, I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is: DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3. DATABASE_USER = 'postgres' # ...

Create a PDF or Printable version of change_list.html in Django Admin

I would like to add a tool link at the top of my admin change_list.html, which I have already done, and have this link basically be able to produce some sort of printable document version of my models data based off of my current filter settings. Basically a print button in the admin change_list.html. so far I have overridden the chang...

ImportError for django.contrib.markup

Hi all, I am trying to enable markup app in django and added 'django.contrib.markup' to INSTALLED APPS and in my model i import it as "import markdown".. but when i go to db and try to add something, i always get importerror. i guess iit must be about app installation issue or am i missing something? this is how i do it in models.py: ...

(re)Using dictionaries in django views

Hello I have this dictionary in my apps model file: TYPE_DICT = ( ("1", "Shopping list"), ("2", "Gift Wishlist"), ("3", "test list type"), ) model, which uses this dict is this: class List(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=200) type = models.PositiveIntegerFi...

Django inlines, how i know which was edited?

Hi guys, i would like to know , how ill know which inlines forms was edited? In my case i want to save a custom value for every inlines form when was edited, so, how i know how much was edited or which one? thanks ...

Python: convert seconds to hh:mm:ss

Hi, Please, how to convert an int (number a seconds) to these formats: mm:ss or hh:mm:ss ? I need to do this with Python code (and if possible in a Django template ?). Thank you very much ;-) ...

Where should one place the code to autoincrement a sharded counter on Google App Engine/Django when one creates a new model?

I've a model MyModel (extending Google's db.Model), and I want to keep track of the number of Models that have been created. I think the code at from Google's I/O talk on Sharding Counters is quite good, so I'm using that. But I'm not sure where I ought to be calling the increment when creating a new code. (I'm using Django, and I've ke...

Django admin and showing thumbnail images

I'm trying to show thumbnail images in Django admin, but I can only see the path to the images, but not the rendered images. I don't know what I'm doing wrong. Server media URL: from django.conf import settings (r'^public/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT}), Function model: def image_i...

django fixtures: Where to add a fixture file

Hi! I am trying to create a set of test case to cover my django application. I need pre defined database data, to run some of my test. So I decided to use fixtures. What I did was: 1) created fixture file: oleg$ python manage.py dumpdata goserver > fixture1.json 2) Placed the fixture in the directory where application lives oleg...

[Django] Group Input in Forms

Hi! I've this django form class CustomerForm(forms.Form): first_name = forms.CharField(label=_('Nome'), max_length=30) last_name = forms.CharField(label=_('Cognome'), max_length=30) business_name = forms.CharField(label=_('Ragione Sociale'), max_length=100) ...

Filtering on related objects when using annotations in Django

Imagine for a moment that I have a system that allows users to take notes. I've got a User model and a Note model: class User(models.Model): name = models.TextField() class Note(models.Model): contents = models.TextField() user = models.ForeignKey(User) created_at = models.DateTimeField(auto_now_add=True) I'd like to ...

Django package multiple files in a single download

In Django I'm looking for a way to serve several different files at once. I can't use static archives (.zip, .tar, etc.) because I don't have enough storage to cache these files and it will take far too long to generate them on the fly (each could be in the 100s of megabytes). Is there a way I can indicate to the browser that several fi...

Disallow user's last name in username

Using the Django framework, I've built a user-based web application. After some time, my client requested that the application disallow creating usernames that contain users' last names. I have two questions: Is it possible to do this reliably, always catching someone trying to register a username containing their last name, which is ...

Django : select_related with ManyToManyField

I have : class Award(models.Model) : name = models.CharField(max_length=100, db_index=True) class Alias(models.Model) : awards = models.ManyToManyField('Award', through='Achiever') class Achiever(models.Model): award = models.ForeignKey(Award) alias = models.ForeignKey(Alias) count = models.IntegerField(default=1) ...

Django preview, TypeError: 'str' object is not callable

I'm trying to make a Preview function. I'm reading this blog, Django Admin Preview, but now I have the following error and I don't know what it means. Traceback (most recent call last): File "/home/user/webapps/django/lib/python2.5/django/core/handlers/base.py", line 92, in get_response response = callback(request, *cal...