django-admin

How to make fields readonly while updating.

I have a form. Once the form is filled I don't want the user to change anything in the form. But the user can see the values. Meaning all the fields are non editable. I can do this by using instance method but this does not help in foreignkey. ...

Image and video previews in admin inline forms for ManyToMany relation

A have 3 models: Project, Image and Video with ManyToManyField relation: class Project(models.Model): images = models.ManyToManyField('Image', through='Project_Images') video = models.ManyToManyField('Video', through='Project_Video') class Image(models.Model): original = models.ImageField() projects = models.ManyToManyF...

European date input in Django Admin

Django has a DATE_FORMAT and a DATE_TIME_FORMAT options that allow us to choose which format to use when viewing dates, but doesn't apparently let me change the input format for the date when editing or adding in the Django Admin. The default for the admin is: YYYY-MM-DD But would be awesome to use: DD-MM-YYYY Is this integrated in an...

How to extend django admin select?

Django creates a search box on the list display page when the field "search_fields" is included in a ModelAdmin. Some of my inline models refer to the items on the list page. If the search box terms match fields in these inline models, I'd like the results to include the referents in the list. Example: Database has a table of names and...

django inline issue

I have made a inline named as Fooinline. This inline was working fine in Django 1.02 but as soon as I upgraded to Django 1.1 it started giving an error: **TypeError at /admin/casd/aaas/4028cb901dd9720a011deadd85e8007f/ __init__() got an unexpected keyword argument 'request'** My Fooinline code is: class FooInline(InlineModelAdmin): ...

Resize fields in Django Admin

Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars. How can I tell the admin how wide a textbox should be, or the he...

How can I get the Django admin's "View on site" link to work?

I've been working with a Django app for a while, and the Django admin interface works great, except that the "View on site" link doesn't work. Whenever I try to use it, I get an OperationalError with the message: no such table: django_site. I've done some research into this problem, and it seems that I have to set up the Django sites fra...

Admin Form Validation

I've got a Supplier Invoice (SupplierInvoice) parent model that holds a number of orders (SupplierOrder). Right now if the user puts together an invoice via django admin, django checks to see if there are price matches for that Supplier and Product in a cost price table and pulls through the respective fields. This process happens on a...

view on site

I am using def get_absolute_url in my model. It is giving the wrong "View on Site" link. How can it be corrected? ...

template django

how can i use different template in different application.in a project i have two app 1)Site 2)Ad .I want to use default template in Ad but different in Site..How to ?OR in the template is there is a way to use 'if condition' as i have to change only two lines in the templates. ...

after upgrade to python2.6 and ubuntu 9.0, django admin does not load css even though admin media is properly configured.

basically i upgraded ubuntu to juanty, and with it came python2.6 so i decided to take the chance and make django work with it. i re-svn'd django into dist-packages, and made sure to properly sym-link my admin media. Note that i'm not using apache, rather just the django development server. when i load up the admin the css seems to not...

Reorder users in django auth

I have a model that has a ForeignKey to the built-in user model in django.contrib.auth and I'm frustrated by the fact the select box in the admin always sorts by the user's primary key. I'd much rather have it sort by username alphabetically, and while it's my instinct not to want to fiddle with the innards of Django, I can't seem to fi...

Creating an order in Django

Hi everyone I have a few questions about the django admin. First the relevant details. I currently have Client, Printer, Cartridge, and Order models. The Printer model has a ManyToManyField to the Cartridge model, which would allow you to select all the cartridges that can be used with that printer. The Cliente has a ManyToManyField t...

django admin foreignkey default value

How can I set a default value on a ForeignKey field in a django Model or AdminModel? Something like this (but of course this doesn't work)... created_by = models.ForeignKey(User, default=request.user) I know I can 'trick' it in the view, but in terms of the AdminModel it doesn't seem possible. ...

changing options according to the user choice

Hi, In my class I have about 12 fields. One field is status, another is reason. When I go to the edit page in the django admin, I only want to show the second field (reason field) if the status=='rejected'. The problem is very simple: just showing the fields according to the user input. ...

How to store the name of user logged in?

I want to store the name of the user who is currently logged into Django in a custom form. In the admin we can do so by writing modified_by=request.user.username, but how do I do this in my own form? ...

Django can't http request its own pages?

At one point, my Django app needs to load one of its own pages to render another page. I'm trying to use urllib2 (working with Python 2.6) to load the page, but it appears that the newer request is blocked until the former completes. Is this a problem with Django using only one thread in debug mode? (I'm running it simply with the defau...

Problem of creating new generic related object inside admin generic inline forms

I have strange problem with admin generic inline forms. I have two models, main Project and Video with ManyToMany relation trough VideoLink, becouse I need to be able linking different number of Video to Project and many project to Video: class VideoLink(models.Model): content_type = models.ForeignKey(ContentType) object_id = mo...

Difference between admin.site.root and admin.site.urls

In the The Django Book in chapter 6 about the Admin Site, they tell me to add the follwing URLpattern to urls.py: urlpatterns = patterns('', # ... (r'^admin/', include(admin.site.urls)), # ... ) But to make it work on my system, I had to uncomment the following line: (r'^admin/(.*)', admin.site.root), Can somebody enlig...

Form widget for text inputs with external link wanted!

I keep field imdb_id for models Movie in my db: class Movie(models.Model): imdb_id = models.IntegerField('imdb ID', blank=True, null=True, unique=True) def _get_imdb_url(self): return self.imdb_id and 'http://www.imdb.com/title/tt%s/' % str(self.imdb_id).zfill(7) or '' def _set_imdb_url(self, imdb_url): sel...